Must declare the scalar variable "@startdate".?

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

It shows the following error?Must declare the scalar variable "@startdate".

public void reportsgridview()
{
SqlConnection con = new SqlConnection("data source=mars-104;initial catalog=marsweb;integrated security=true");
SqlCommand cmd = new SqlCommand("select compname,compaddress,invoiceno,orderno,convert(varchar,ondate,105),convert(varchar,invoicedate,105),amountstatus,netamount,netvat,tamount from tbl_report2 where invoicedate between @startdate and @enddate order by invoicedate asc", con);// Here it shows the error:Must declare the scalar variable "@startdate".?
cmd.Parameters.AddWithValue("@startdate", Convert.ToDateTime(txt_startdate.Text));
cmd.Parameters.AddWithValue("@enddate", Convert.ToDateTime(txt_enddate.Text));
con.Open();

SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
if (dt.Rows.Count > 0)
{
GridView1.DataSource = dt;
}
else
{
MessageBox.Show("no record found");
}
}

Best,
Sudheep.



Responses

Posted by: Vuyiswamb on: 11/9/2011 [Member] [MVP] [Administrator] NotApplicable | Points: 25

Up
0
Down
try to remove the @ signs

cmd.Parameters.AddWithValue("startdate", Convert.ToDateTime(txt_startdate.Text));

cmd.Parameters.AddWithValue("enddate", Convert.ToDateTime(txt_enddate.Text));


Thank you for posting at Dotnetfunda
[Administrator]

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

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

Up
0
Down
Hi,

I am removing the @sign's it's wont work.can you please help me.

Best,
Sudheep.

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

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

Up
0
Down
Hi,

I am not able to find any error in your code. Once you test where the error is prodcued.

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

Up
0
Down
Hi,

Is there any option for gridview1_rowcommand() in windows applications?even i am searching the property it will not availlable in properties also.my intension is i have to bind the data to gridview.please do the needful.

Best,
Sudheep.

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

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

Up
0
Down
Hi,

I can't understand your problem. Can you provide the screen shot of your screen that shows datagrid with data.

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