Click here to Skip to main content
15,886,689 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I want to search date using
cmd.Parameters.add 
i have one column for date time
here i can serach for single date . i want in between dates .



C#
SqlCommand cmd = new SqlCommand("SELECT report_type,count (report_type) as Count1 FROM Transactions where   dateadd(dd, datediff(dd,0, [R_date]), 0) =@R_date group by report_type");
cmd.Connection = con;
cmd.Parameters.Add("@R_date", SqlDbType.DateTime).Value = dtime.Date;
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
Posted

1 solution

Try:
SQL
SELECT report_type,count (report_type) AS Count1 FROM Transactions WHERE R_Date BETWEEN @STARTDATE AND @ENDDATE
Then just provide teh start and end date values via parameters.

BTW: You do know you can use Parameters.AddWithValue instead?
C#
cmd.Parameters.AddWithValue("@STARTDATE", dtime.Date);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900