if i am try to update my form it shows the following errors?

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

if i am try to update my form it shows the following errors?.please do the needful.
Error:
Incorrect syntax near '@ondate'.

private void btn_add_Click(object sender, EventArgs e)
{
//SqlConnection con=new SqlConnection ("data source=mars-104;initial catalog=marsweb;integrated security=true");
DBConnection db = new DBConnection();
SqlConnection con = db.opencon();
SqlCommand cmd=new SqlCommand ("insert into tbl_report1(particulars,quantity,perprice,amount,invoicedate,ondate)values(@particulars,@quantity,@perprice,@amount,@invoicedate,@ondate",con );
cmd .Parameters .AddWithValue ("@invoiceid",txt_invoiceno .Text );
cmd .Parameters .AddWithValue ("@particulars",cmb_particulars .Text );
cmd .Parameters .AddWithValue ("@quantity",txt_quantity .Text );
cmd .Parameters .AddWithValue ("@perprice",txt_perprice .Text );
cmd .Parameters .AddWithValue ("@amount",txt_amount .Text );
cmd .Parameters .AddWithValue ("@orderno",txt_orderno .Text );
cmd .Parameters .AddWithValue ("@compname",cmb_companyname .Text );
cmd.Parameters.AddWithValue("@invoicedate", txt_invoicedate.Text);
cmd.Parameters.AddWithValue("@ondate", txt_ondate.Text);
SqlDataAdapter da=new SqlDataAdapter ();
if (con.State == ConnectionState.Closed)
{
con.Open();
}
cmd .ExecuteNonQuery ();//error shows here as incorrect syntax near @ondate
con .Close ();

SqlConnection conn=new SqlConnection ("data source=mars-104;initial catalog=marsweb;integrated security=true");
SqlCommand cmd1=new SqlCommand ("select particulars,quantity,perprice,amount from tbl_report1 where orderno=@id",conn );
cmd1 .Parameters .AddWithValue ("@id",id );
SqlDataAdapter da1=new SqlDataAdapter (cmd1 );
con .Open ();
DataTable dt=new DataTable ();
cmd1 .ExecuteNonQuery ();
da1 .Fill (dt );
GridView1 .DataSource =dt ;
con .Close ();
vatamount ();
vatdata ();
netamount ();
txt_quantity .Text ="";
txt_perprice .Text ="";
txt_amount .Text ="";


}

Best,
Sudheep.



Responses

Posted by: Sksingh on: 11/21/2011 [Member] Starter | Points: 25

Up
0
Down
Hi Sudheep,

You get message because of missing of closing parentheses of Values

("insert into tbl_report1(particulars,quantity,perprice,amount,invoicedate,ondate)values(@particulars,@quantity,@perprice,@amount,@invoicedate,@ondate) ",con );


Regards,
Sunil

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

Login to post response