Logo 
Search:

Asp.net Forum

Ask Question   UnAnswered
Home » Forum » Asp.net       RSS Feeds

error in c#

  Asked By: Asksuresh    Date: Jan 09    Category: Asp.net    Views: 718
  

i got error:


while (objDataReader.Read())

{

db_pageID = objDataReader["id"];

}//end while



cannot convert object to int

db_pageID var is integer.

Share: 

 

4 Answers Found

 
Answer #1    Answered By: Mamie Wallace     Answered On: Jan 09

Try:
db_pageID = Convert.ToInt32(objDataReader["id"]);

 
Answer #2    Answered By: Randy Warren     Answered On: Jan 09

(int)objDataReader["id"];
or
int.Parse(objDataReader["id"].ToString());

 
Answer #3    Answered By: Frederick Greene     Answered On: Jan 09

Might need to check for a null value first.


if(objDataReader["id"] != System.DbNull.Value)
db_pageID = (int)objDataReader["id"];
else
db_pageID = -1;

 
Answer #4    Answered By: Julian Long     Answered On: Jan 09

ids = ids + Convert.ToString(ds.Tables[0].Rows[i].ItemArray["id"]) + ",";

cannot convert  string to int

 
Didn't find what you were looking for? Find more on error in c# Or get search suggestion and latest updates.




Tagged: