Simply put, how do I write this same filter in my C# code?
select * from [dbo].[xtblMROrderItems] where (convert(varchar(10), [ReceivedDate], 101)) = '06/24/2021'
I am trying to see if all rows in the datatable that I've populated in my application have the same date without regard to the timestamp.
So the C# code goes like this:
Or went like that before I changed column ReceivedDate in the table schema to be type datetime. Now I have to somehow strip off the time.
Before I do it brute force; that is, get the first row and loop through all the rows comparing one by one, I wanted to try to get this filter working. But I am having a hard time getting the datatypes and synatx right.
Here is the (bad) fruit of my labor over the past hour... (FYI I started hardcoding the date to 6/24/21 just to simplify it and get rid of a variable, but ultimately that will be the date of the first row that I want to compare all remaining rows to. e.DisplayText is the value of a grid cell and I want it to display the date if they all match or an * if any are on different days).
Thank you!
select * from [dbo].[xtblMROrderItems] where (convert(varchar(10), [ReceivedDate], 101)) = '06/24/2021'
I am trying to see if all rows in the datatable that I've populated in my application have the same date without regard to the timestamp.
So the C# code goes like this:
Code:
DateTime rcvdDate = drItems.ReceivedDate;
string sFilter = String.Format("ReceivedDate = '{0}'", rcvdDate);
//dv = new DataView(dtItems, sFilter, "", DataViewRowState.CurrentRows);
//if (dv.ToTable().Rows.Count == dtItems.Rows.Count)
// e.DisplayText = rcvdDate.ToString("MM/dd/yyyy");
//else
// e.DisplayText = "*";
Before I do it brute force; that is, get the first row and loop through all the rows comparing one by one, I wanted to try to get this filter working. But I am having a hard time getting the datatypes and synatx right.
Here is the (bad) fruit of my labor over the past hour... (FYI I started hardcoding the date to 6/24/21 just to simplify it and get rid of a variable, but ultimately that will be the date of the first row that I want to compare all remaining rows to. e.DisplayText is the value of a grid cell and I want it to display the date if they all match or an * if any are on different days).
Code:
//sFilter = String.Format("CONVERT(Date, [ReceivedDate]) = '{0}'", rcvdDate.Date);
//dv = new DataView(dtItems, sFilter, "", DataViewRowState.CurrentRows);
//if (dv.ToTable().Rows.Count == dtItems.Rows.Count)
// e.DisplayText = rcvdDate.ToString("MM/dd/yyyy");
//else
// e.DisplayText = "*";
//sFilter = String.Format("convert(CONVERT([ReceivedDate], 'System.DateTine'), 'System.String') Like '{0}%'", rcvdDate.Date);
sFilter = String.Format("convert(CONVERT([ReceivedDate], 'System.DateTime'), 'System.String') Like '{0}%'", "6/4/2021");
dv = new DataView(dtItems, sFilter, "", DataViewRowState.CurrentRows);
if (dv.ToTable().Rows.Count == dtItems.Rows.Count)
e.DisplayText = rcvdDate.ToString("MM/dd/yyyy");
else
e.DisplayText = "*";
// It has to go something like this:
// select * from [dbo].[xtblMROrderItems] where (convert(varchar(10), [ReceivedDate], 101)) = '06/24/2021'
sFilter = "(convert(varchar(10), [ReceivedDate], 101)) = '06/24/2021'";
dv = new DataView(dtItems, sFilter, "", DataViewRowState.CurrentRows);