Table - tblData (Data for Jan.):
This is how I see the data with select * from tblData
ID Tag Date
1 OB 2014-07-01
2 OC 2014-07-01
3 AB 2014-07-01
Trying to achieve the same from C#, but this is not working.
DateTime dtFrom = Convert.ToDateTime(txtFromDate.Text.Trim(),System.Globalization.
CultureInfo.GetCultureInfo("hi-IN").DateTimeFormat);
DateTime dtTo = Convert.ToDateTime(txtToDate.Text.Trim(),System.Globalization.
CultureInfo.GetCultureInfo("hi-IN").DateTimeFormat);
gridview1.DataSource = objDAL.GetData(dtFrom,dtTo);
gridview1.DataBind();
Here's the SQL Server 2008 R2 stored procedure
Alter Procedure GetData
(
@DateFrom Date, @DateTo Date
)
As
Begin
Select * from tblData
where date between @DateFrom and @DateTo
End
No rows are returned with the above query, and I believe this could be due to the date formats. How can this be solved? Not sure if it has to be changed in code or in the stored procedure.
EDIT:
- The dates in the textboxes are -
08-01-2013 - In code behind
dtFrombecomes -1/8/2013 12:00:00 AM - The datatype for 'date' column is just date and not datetime
GetData in DAL
public DataTable GetData(DateTime dtfrom, DateTime dtto)
{
var qry = from p in MyDB.GetData(dtfrom,dtto)
select new
{
id = p.id,
tag = p.tag,
date = p.date
}
dt = qry.ToDataTable();
return dt;
}
The problem's not with the dal code. It executes fine. The row count is 0. So I'm sure its the diff. date formats.
drFromanddtTo?