SqlExecption was unhandled?

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


In code.it shows the error as SqlExecption was unhandled?
cmd.ExecuteNonQuery();

Best,
Sudheep.



Responses

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

Up
0
Down
Can you list out complete exception you got?

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

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

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

Up
0
Down
HI,

Incorrect syntax near '@tamount'.
SqlCommand cmd = new SqlCommand("insert into tbl_report2 (compname,compaddress,orderno,ondate,invoicedate,amountstatus,netamount,netvat,tamount)values(@compname,@compaddress,@orderno,@ondate,@invoicedate,@amountstatus,@netamount,@netvat,@tamount", con);


Best,
Sudheep.

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

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

Up
0
Down
Hi,
You missed to add the close bracket ")" after @tamount. add this and try again.

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/7/2011 [Member] Starter | Points: 25

Up
0
Down
Hi,

it shows the error as :sqlexception was unhandled.Must declare the scalar variable "@InvoiceNo".
DataTable dt=new DataTable ();
SqlConnection con=new SqlConnection ("data source=mars-104;initial catalog=marsweb;integrated security=true");
con .Open ();
SqlCommand cmd=new SqlCommand ("select CompName,CompAddress,InvoiceNo,OrderNo,OnDate,InvoiceDate,NetAmount,NetVat,TAmount from tbl_Report2 WHERE InvoiceNo= @InvoiceNo",con );
SqlDataAdapter da=new SqlDataAdapter (cmd );
cmd.Parameters .AddWithValue ("@invoiceno");
da .Fill (dt );//it will shows the error



Best,
Sudheep.

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

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

Up
0
Down
hi,

you didn't pass the value for invoiceno in the line cmd.Parameters .AddWithValue ("@invoiceno");
refer http://msdn.microsoft.com/en-us/library/yy6y35y8(v=vs.71).aspx

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/7/2011 [Member] Starter | Points: 25

Up
0
Down
Hi,

I am passing invoice no again it shows the error.here is my code.

DataTable dt=new DataTable ();
SqlConnection con=new SqlConnection ("data source=mars-104;initial catalog=marsweb;integrated security=true");
con .Open ();
SqlCommand cmd=new SqlCommand ("select compname,compaddress,invoiceno,orderno,ondate,invoicedate,netamount,netvat,tamount from tbl_Report2 WHERE invoiceno=@invoiceno )",con );
SqlDataAdapter da=new SqlDataAdapter (cmd );
cmd.Parameters .AddWithValue ("@invoiceno");
da .Fill (dt );//error shows here

Best,
Sudheep.

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

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

Up
0
Down
Hi,

Refer the link http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlparametercollection.addwithvalue.aspx
and corect your code with this example.

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

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

Login to post response