Reputation: 4216
I have a DataTable resultSet;
- I'm trying to check fields for null, but get an '{}' (empty-set ?) object back. Searches involving "{}" aren't yielding any appropriate solutions.
This is the code that isn't working as expected when the "fk_id" field is null:
if (resultSet.Rows[0].ItemArray[resultSet.Columns.IndexOf("fk_id")] == null)
{
//never reaches here
}
Note: using an int index instead of the Columns.IndexOf()
isn't the issue.
Also does the "{}" have some other name in C#?
Upvotes: 11
Views: 26543
Reputation: 161
Please use:
dataTable.Select("FieldName is NULL")
this will give you the DataRows with null values in FieldName column.
Upvotes: -2
Reputation: 1
try
{
if (DT.Rows[0][0] != null)
{
//your code
}
}
catch
{
MessageBox.Show("AUTHANICATION FAILED.");
}
Upvotes: -2
Reputation: 204229
To check a column for DBNull in a DataSet, you can use the IsNull method:
if (resultSet.Rows[0].IsNull("fk_id"))
Your comparison against null
is probably failing because DataSets don't use null
to represent a "database NULL" value - they use DBNull.Value. If you need your code to work the way you've presented it, try this:
if (resultSet.Rows[0].ItemArray[resultSet.Columns.IndexOf("fk_id")] == DBNull.Value)
Upvotes: 19