I want to validate if the field really exist in the table in the database. I have used the SqlDataReader class for the reading of data. After assigning the value to the SqlDataReader I made a loop to iterate each record using foreach. Here is the sample code.
SqlCommand sqlCommand = new SqlCommand();
SqlDataReader sqlDr = sqlCommand.ExecuteReader();
Foreach(DbDataRecord record in sqlDr)
{
// Validate if the value is not null and (I want to validate if this field really exist in the table)
if(record["MyField1"].GetType().ToString() == "System.DBNull")
{
// Statement here
}
}
I hope for a kind answer. Thank you very much.
I would write an
extensionmethod which iterates thru each fields in the reader and return true/false.Then call it like this