JasonWinn
asked on
Filtering DataGridView with Date Cannot perform '=' operation on System.DateTime and System.String
Error Message: Cannot perform '=' operation on System.DateTime and System.String
I have a Dataset with date values that look like "11/23/2006" , that format.
I am trying to use a combobox to sort datagridview to only show things concerning tomorrow.
Pretty simple but I keep getting that error message. I have made my column in the dataset a String type
string dt = DateTime.Today.AddDays(01) .ToShortDa teString() ;
if (sortBox.Text == "Due Tomorrow")
{
dsAssignment.assignmentsTa ble.Defaul tView.RowF ilter = "dueDate = " + dt + "";
}
else
{
}
I have a Dataset with date values that look like "11/23/2006" , that format.
I am trying to use a combobox to sort datagridview to only show things concerning tomorrow.
Pretty simple but I keep getting that error message. I have made my column in the dataset a String type
string dt = DateTime.Today.AddDays(01)
if (sortBox.Text == "Due Tomorrow")
{
dsAssignment.assignmentsTa
}
else
{
}
ASKER
hey DrAske,
I gave that a shot but it is not filtering for some reason. I get no error message but it does not filter. I have records in the "dueDate" column for tomorrow (11/29/2006) and everything appears to be correct but not filtering happening
any ideas?
thanks
private void sortBox_SelectedIndexChang ed(object sender, EventArgs e)
{
string dt = DateTime.Today.AddDays(01) .ToShortDa teString() ;
if (sortBox.Text == "Due Tomorrow")
{
dsAssignment.assignmentsTa ble.Defaul tView.RowF ilter = "dueDate = '" + dt + "'";
this.assingmentListDataGri dView.Refr esh();
}
else
{
}
}
I gave that a shot but it is not filtering for some reason. I get no error message but it does not filter. I have records in the "dueDate" column for tomorrow (11/29/2006) and everything appears to be correct but not filtering happening
any ideas?
thanks
private void sortBox_SelectedIndexChang
{
string dt = DateTime.Today.AddDays(01)
if (sortBox.Text == "Due Tomorrow")
{
dsAssignment.assignmentsTa
this.assingmentListDataGri
}
else
{
}
}
>>I gave that a shot but it is not filtering for some reason
That means the first Error Msg has gone.
>> I get no error message but it does not filter
what kind of errors?? compile-time error or it gives you an exception??
>> string dt = DateTime.Today.AddDays(01) .ToShortDa teString() ;
If you try to print out *dt* you will get something like this "11/29/2006 12:00:00 AM", and I think that's why no filtering happens !! So try this:
private void sortBox_SelectedIndexChang ed(object sender, EventArgs e)
{
string dt = DateTime.Today.AddDays(01) .ToShortDa teString() ;
string[] d = dt.split(' '); // tokenize the string
if (sortBox.Text == "Due Tomorrow")
{
dsAssignment.assignmentsTa ble.Defaul tView.RowF ilter = "dueDate = '" + d[0]+ "'"; // d[0] is "11/29/2006"
this.assingmentListDataGri dView.Refr esh();
}
else
{
/// ...
}
}
try it, and post back the result..
regards,Ahmad;
That means the first Error Msg has gone.
>> I get no error message but it does not filter
what kind of errors?? compile-time error or it gives you an exception??
>> string dt = DateTime.Today.AddDays(01)
If you try to print out *dt* you will get something like this "11/29/2006 12:00:00 AM", and I think that's why no filtering happens !! So try this:
private void sortBox_SelectedIndexChang
{
string dt = DateTime.Today.AddDays(01)
string[] d = dt.split(' '); // tokenize the string
if (sortBox.Text == "Due Tomorrow")
{
dsAssignment.assignmentsTa
this.assingmentListDataGri
}
else
{
/// ...
}
}
try it, and post back the result..
regards,Ahmad;
ASKER
Hey Ahmad,
I gave it a shot, and no error message, but no filtering.
I made a label.Text = d[0]; and the result was "11/30/2006" so its doing the correct date, but not sure why it isnt actually filtering.
Jason
I gave it a shot, and no error message, but no filtering.
I made a label.Text = d[0]; and the result was "11/30/2006" so its doing the correct date, but not sure why it isnt actually filtering.
Jason
ASKER
Maybe there is an easier way? All I would like to be able to do is filter out date's/ranges of my datagridview/dataset.
my goal is to have the user click "filter by things for tomorrow" or "filter for things this week".
maybe there is something easier for filtering with dates?
Jason
my goal is to have the user click "filter by things for tomorrow" or "filter for things this week".
maybe there is something easier for filtering with dates?
Jason
ASKER
Maybe the problem is elsewhere, even doing this not filter out things for 11/30/2006, everything remains visible
if (sortBox.Text == "Due Tomorrow")
{
dsAssignment.assignmentsTa ble.Defaul tView.RowF ilter = "dueDate = '11/30/2006'"; // d[0] is "11/29/2006"
assingmentListDataGridView .Refresh() ;
}
else
{
/// ...
}
if (sortBox.Text == "Due Tomorrow")
{
dsAssignment.assignmentsTa
assingmentListDataGridView
}
else
{
/// ...
}
ASKER
I am really confused now.... even a simple statement like this is not working.
If I have this right, this should only display rows containing "hi" in the description column in my DataGridView?
this.dsAssignment.assignme ntsTable.D efaultView .RowFilter = "description = 'hi'";
// Does Not Work
If I have this right, this should only display rows containing "hi" in the description column in my DataGridView?
this.dsAssignment.assignme
// Does Not Work
OK!! I can't see anything wrong in your code!! but try to add output statement inside the *if* statement to notify you when it is executed. If it doesn't!! then the problem is in the *if* condition.
if (sortBox.Text == "Due Tomorrow")
{
MessageBox.Show("IT'S OK!!");
dsAssignment.assignmentsTa ble.Defaul tView.RowF ilter = "dueDate = '11/30/2006'"; // d[0] is "11/29/2006"
assingmentListDataGridView .Refresh() ;
}
if (sortBox.Text == "Due Tomorrow")
{
MessageBox.Show("IT'S OK!!");
dsAssignment.assignmentsTa
assingmentListDataGridView
}
ASKER
Hey DrAske,
I did that and that works fine and the messagebox comes up.
Whats really interesting is, I made label1.Text = d[0], and the label would show 11/30/2006....
im wondernig if it is because my dataset is being loaded from an xml file? the xml file shows 11/30/2006, without any hours, minutes or seconds.
Thanks for your help so far!
jason
I did that and that works fine and the messagebox comes up.
Whats really interesting is, I made label1.Text = d[0], and the label would show 11/30/2006....
im wondernig if it is because my dataset is being loaded from an xml file? the xml file shows 11/30/2006, without any hours, minutes or seconds.
Thanks for your help so far!
jason
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
add single quote
dsAssignment.assignmentsTa