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());
}

VulpesRank #55 · 29.2K reputationPosted Dec 9, 2011, 2:05 AM EST
http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqldatareader.isdbnull.aspx
Zeb Rehman41 reputationPosted Dec 9, 2011, 8:50 AM EST