C# Winforms Listbox filtering Datagridview by Date

So, I have an excel file with column "settlement date" with this format: dd/mm/yyyy. I send this over a SQL column within a "date" format where the format changes automatically in yyyy-mm-dd. Then when I send this SQL column to a C# Winforms listbox using:

SqlCommand cmd = new SqlCommand(sqlStr, conn);
SqlDataReader rd = cmd.ExecuteReader();
while (rd.Read())

the dates are displayed again in dd/mm/yyyy (the same format I had on excel) and eventually when I'm trying to filter a datagridview by settlement date using my listbox just filled, I've got the following error message:

"Conversion failed when converting date and/or time from character string".

I read a few things so far but I'm a bit confused here, should I change the format directly from the start (excel table) to SQL server or maybe change within SQL from format "date" to "string" and once in winform, just sorting as it would be a string ?

Let me know if it doesn't sound very clear or you need more info


Read more here: https://stackoverflow.com/questions/66337778/c-sharp-winforms-listbox-filtering-datagridview-by-date

Content Attribution

This content was originally published by Pierre_CM at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: