Specified Cast is not Valid - driving me nuts!
-
Why am I getting this error? My stored procedure is returning the value of an int column... try { SqlDataReader r = run_sql_reader(sql); if (r.Read()) { LB_CO_record_number.Text = (r.GetInt32(0)).ToString(); //***exception here } r.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } Visual Studio is not telling me what is trying to be casted to what else, so I can't figure out which thing is causing the error. I do this kind of thing all the time and I've never gotten this error. "Quality Software since 1983!"http://www.smoothjazzy.com/ - see the "Programming" section for freeware tools and articles.
-
Why am I getting this error? My stored procedure is returning the value of an int column... try { SqlDataReader r = run_sql_reader(sql); if (r.Read()) { LB_CO_record_number.Text = (r.GetInt32(0)).ToString(); //***exception here } r.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } Visual Studio is not telling me what is trying to be casted to what else, so I can't figure out which thing is causing the error. I do this kind of thing all the time and I've never gotten this error. "Quality Software since 1983!"http://www.smoothjazzy.com/ - see the "Programming" section for freeware tools and articles.
Mmmmkay... I figured it out. My proc was for some reason not returning an int column. I don't know what it was returning, but using "convert" on the value before sending it back fixed the problem. Crazy computers :)
"Quality Software since 1983!"
http://www.smoothjazzy.com/ - see the "Programming" section for freeware tools and articles. -
Mmmmkay... I figured it out. My proc was for some reason not returning an int column. I don't know what it was returning, but using "convert" on the value before sending it back fixed the problem. Crazy computers :)
"Quality Software since 1983!"
http://www.smoothjazzy.com/ - see the "Programming" section for freeware tools and articles.By any chance did you get a NULL returned from the database. Attempting to convert NULL to another might succumb with
System.InvalidCastException: The specified cast is invalid
.Vasudevan Deepak Kumar Personal Homepage Tech Gossips
Yesterday is a canceled check. Tomorrow is a promissory note. Today is the ready cash. USE IT. -
By any chance did you get a NULL returned from the database. Attempting to convert NULL to another might succumb with
System.InvalidCastException: The specified cast is invalid
.Vasudevan Deepak Kumar Personal Homepage Tech Gossips
Yesterday is a canceled check. Tomorrow is a promissory note. Today is the ready cash. USE IT.No it returns a number, which I verified, but it's good to know that. I'll add some code to check for that. Thanks!
"Quality Software since 1983!"
http://www.smoothjazzy.com/ - see the "Programming" section for freeware tools and articles.