Input string was not in a correct format.Couldn't store <emp8> in id Column. Expected type is Int32

Posted by Himanshu001 under C# on 5/3/2013 | Points: 10 | Views : 3024 | Status : [Member] | Replies : 3
protected void Button1_Click(object sender, EventArgs e)
{
c.cmd.CommandText = "select * from newuser";
c.adp.Fill(c.ds, "vT");
c.dr = c.ds.Tables["vT"].NewRow();
c.dr["id"] =c.auto_id("emp",c.ds.Tables["vT"].Rows.Count);//i am getting error here
c.dr["username"] = txtusername.Text;
c.dr["first_name"] = txtfname.Text;
c.dr["password"] = passtxt.Text;
c.dr["image"] = "~//new_user_image/" + ImgUpload.FileName;
c.dr["phone"] = txtphone.Text;
c.dr["email"] = emailtxt.Text;
c.dr["status"] = "false";
c.dr["login_status"] = "false";
c.ds.Tables["vT"].Rows.Add(c.dr);
c.cb = new SqlCommandBuilder(c.adp);
c.adp.Update(c.ds.Tables["vT"]);
ImgUpload.SaveAs(Server.MapPath("~//new_user_image/" + ImgUpload.FileName));
Response.Redirect("success_signup.aspx");

}

i am getting error please tell me how to resolve it


himanshu


Responses

Posted by: Raja_89 on: 5/3/2013 [Member] Starter | Points: 25

Up
0
Down
Hai
This is due to the input value[Value to be stored ] is greater than

Try like this

cmd.Parameters.Add ("@St_Name",SqlDbType.Bit );

or
convert the text box value int32

cmd.Parameters.Add("@St_Name", Convert.ToInt32(NamesSText.Text));

Regards


Himanshu001, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Himanshu001 on: 5/3/2013 [Member] Starter | Points: 25

Up
0
Down
thanks,but could u please explain in context of the above code.i'm not getting it...

himanshu

Himanshu001, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Nadeemshaik on: 5/8/2013 [Member] Starter | Points: 25

Up
0
Down
You are assigning string value to integer column..

you have to convert that string into integer

Himanshu001, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response