Sqlexception was unhandled?

Posted by Sudheep.grandhe under C# on 11/21/2011 | Points: 10 | Views : 1690 | Status : [Member] | Replies : 1
Hi,

in coding it shows the following error.please do the needful.

Error:
Conversion failed when converting the nvarchar value 'HB001' to data type int.
public partial class UpdateCustomerInvoice : Form
{

int id2=1;
}
public void getgriddata()
{
DataTable dt = new DataTable();
SqlConnection con = new SqlConnection("data source=mars-104;initial catalog=marsweb;integrated security=true");
con.Open();
SqlCommand sqlcmd = new SqlCommand("select particulars,quantity,perprice,amount from tbl_report1 where orderno=@invoiceno", con);
SqlDataAdapter sqlda = new SqlDataAdapter(sqlcmd);
sqlcmd.Parameters.AddWithValue("@invoiceno", id2);//here it passes the id2 value =1
sqlda.Fill(dt);//error:sqlexception was unhandled
GridView1.DataSource = dt;
txt_customeraddress.Text = "";
}

Best,
Sudheep.



Responses

Posted by: SheoNarayan on: 11/21/2011 [Administrator] HonoraryPlatinum | Points: 25

Up
0
Down
The error you are getting is self explanatory

It is not able to convert "HB001" to integer. So see that you have not mismatched the data types. May be id2 has some wrong value.

Thanks

Regards,
Sheo Narayan
http://www.dotnetfunda.com

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

Login to post response