sqlexecption was unhandled?

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

It show's this error .Parameterized Query '(@id1 nvarchar(4000))select particulars,orderno,quantity,perpric' expects parameter @id1, which was not supplied.please do the needful.

SqlConnection con1 = new SqlConnection("data source=mars-104;initial catalog=marsweb;integrated security=true");
SqlCommand cmd1 = new SqlCommand("select particulars,orderno,quantity,perprice,amount from tbl_report1 where invoiceid=@id1", con1);
cmd1.Parameters.AddWithValue("@id1", id1);
SqlDataAdapter da1 = new SqlDataAdapter(cmd1);
DataTable dt1 = new DataTable();
da1.Fill(dt1);
if (dt1.Rows.Count > 0)
{
GridView2.DataSource = dt1;
}
else
{
MessageBox.Show("no record found");
}

Best,
Sudheep.



Responses

Posted by: Abdulhaknet on: 11/10/2011 [Member] Starter | Points: 25

Up
0
Down
Hi Friend,

Its better to add parameter id1.datatype i.e. SqlDbType

cmd1.Parameters.AddWithValue("@id1", id1);

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

Posted by: Blessyjees on: 11/10/2011 [Member] Bronze | Points: 25

Up
0
Down
hi,

I have tried same code as you like. I got the corect result. I think that your code is correct.

Blessy Baby
Digitalmesh Softech pvt Ltd
https://blessybaby.wordpress.com/

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

Posted by: Sudheep.grandhe on: 11/10/2011 [Member] Starter | Points: 25

Up
0
Down
Hi,

For me it's giving error.what is the problem?

Best,
Sudheep.

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

Login to post response