haroldjclements
Freshman
- Joined
- Jun 13, 2004
I have a problem with reading null value from my database. The connection works and does retrieve the data. However if there is an empty cell in the database it creates an exception java.lang.classCastException: Specified cast is not valid
I have tried to convert the output to a string, but that did not work. I think that the problem is with the .GetString() line as a blank cell is not a string. This cell is not always empty so .GetString() works fine when it's not.
If anyone could help me I will be eternally grateful
Code:
while (myDataReader.Read())
{
description = myDataReader.GetString(0);
//The error is here!
custPN = System.Convert.ToString(myDataReader.GetString(2));
//custPN = myDataReader.GetString(2);
sql = "SELECT Name FROM tblSupplier WHERE SupplierID = " + myDataReader.GetInt16(1);
}
I have tried to convert the output to a string, but that did not work. I think that the problem is with the .GetString() line as a blank cell is not a string. This cell is not always empty so .GetString() works fine when it's not.
If anyone could help me I will be eternally grateful