Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

convert Int32 to string isn't working

Status
Not open for further replies.

jgillin

Programmer
Oct 22, 2003
82
US
Hi,
I get a Int32 returned from calling dr.GetInt32(3) on an IDataReader, but it won't let me cast this to a string using ToString(). Can anyone tell me why?
Here's a bit of the code:

SqlDataReader dr = (SqlDataReader)dbCommand.ExecuteReader();
dr.Read();
CompanyName.Text=dr.GetString(1);
PackageName.Text=dr.GetString(2);
MinMonthsSinceBankruptcy.Items.FindByValue(dr.GetInt32(3).ToString()).Selected=true;

Thanks for any thoughts.

Jeff

 
That's strange, it should be working that way. Have you tried
Code:
Convert.ToString(dr.GetInt32(3))
? And what specific error do you get when executing this code?

regards,
Blaxo
 
Thanks for the reply.
It turned out that I had 2 problems. The first was that I should have been using GetInt16. The second problem was that the value in the database for this was null, and I needed to check for null before the last line. I did this using :
if(dr[3]!=DbNull.Value){
...
}

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top