I'm facing the problem in following code. In database there is an empty field when i try to read it the error came on console. the code is given following.
It show me the error that System.InvalidCastException: Specified cast is not valid. How to remove the error.....
try
{
conn.Open();
OleDbConnection(connectionString);string sql = "SELECT * FROM 51";OleDbCommand cmd = new OleDbCommand(sql, conn);
reader = cmd.ExecuteReader();
string name = null;
while (reader.Read())
{
if(reader.GetString())
{
Console.WriteLine("Feild Empty");
}
}
}
catch(Exception ex)
{
Console.WriteLine(ex.ToString());
}
Zeb RehmanPosted Dec 9, 2011, 1:50 PM
VulpesPosted Dec 9, 2011, 7:05 AM
http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqldatareader.isdbnull.aspx