Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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�

 

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

  • 2 months later...
  • 3 months later...
Posted

Hello, I know it�s been a long time since your post but I have come across the same problem again.

 

How would you check to see if the item being dragged from the database is null?

 

If I use the �myDataReader.GetString(x)� within an �if� statement then I still get the error, so presumably I need to test the object before the conversion.

 

My question is how?

 

Thanks in advance,

Harold Clements

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...