sql - how to check for null in datarow row in c# -
i have code
foreach (datarow row in dtgraph.rows) { string username = row["username"].tostring(); string loggedstate = row["loggedstate"].tostring(); string interactionid = row["interactionid"].tostring(); string interactiontype = row["interactiontype"].tostring(); }
how check if row["something"]
null?
i tried run code, , null values becomes "" (empty).
i need check if these null.
i stupid question, problem making tostring()
thought null becomes null
or null
or null
or empty?
thanks
use dbnull.value
var username = row["username"].tostring();
to
var username = reader["username"] != dbnull.value ? row["username"].tostring():"";
update
var username = ""; if(reader["username"] != dbnull.value) { username = row["username"].tostring(); }
Comments
Post a Comment