Zeb Rehman

Zeb Rehman

  • NA
  • 41
  • 72.9k

OLEDBReader Porblem

Dec 9 2011 6:56 AM
Hi every body!
                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();



string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;data source=Z:\\ptcl.accdb";OleDbConnection conn = new

OleDbConnection
(connectionString);string sql = "SELECT * FROM 51";OleDbCommand cmd = new OleDbCommand(sql, conn);



reader = cmd.ExecuteReader();



OleDbDataReader reader;String name = null;
string name = null;
while
(reader.Read())
{       
        if(reader.GetString())
        {
                Console.WriteLine("Feild Empty");
        }
}
}

catch(Exception ex)

{

Console.WriteLine(ex.ToString());


}




Answers (2)