|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
System.InvalidCastExceptionTrying to start small and just read a line in from a database to see what happens. Not even really trying to do anything with it yet. When I try to read in the return statement using GetString, I get a System.InvalidCastException. I thought handling the null case would take care of it, but apparently there is something else wrong as well. Here's my code: static void Main() { string databaseReturn = null; OleDbConnection dbConnection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source = ...\\..\\msds.mdb"); OleDbCommand dbCommand = new OleDbCommand("select * from FreeText", dbConnection); try { dbConnection.Open(); } catch (System.Data.OleDb.OleDbException e) { String errMsg = "Error Message: " + e.Message; } OleDbDataReader dbReader = dbCommand.ExecuteReader(); while (dbReader.Read()) { if (dbReader.IsDBNull(0)) databaseReturn = ""; else databaseReturn = dbReader.GetString(0); } dbReader.Close(); dbConnection.Close(); } |
|||||||||||||||||||||||