hi ppl, im using a datatable.select method to filter a datatable, i have a datetime column and i have 2 dateTimePickers.
Im doing the next:
string date;
date = String.Format("Fecha >= #{0}# AND Fecha < #{1}#", dtPickerDesde.Value.ToShortDateString(), dtPickerHasta.Value.AddDays(1).ToShortDateString());
rows = dtFacturas.Select(date);
//rows is my DataRows array
i dont know why it throw me exception with some dates and with some others it dont for example, when the string is like this:
Fecha >= #31/07/2006# AND Fecha < #01/08/2006#
thres no problem
but when its like this:
Fecha >= #31/01/2006# AND Fecha < #01/08/2006#
or this:
Fecha >= #28/02/2006# AND Fecha < #01/08/2006#
it throws an exception, and much more dates throw me exception but i dunno why, can some1 help me
mig16

DateTime select problem
Debugger Zero
Put always datetime in the format MM/dd/yyyy
Fecha >= #02/28/2006# AND Fecha < #08/01/2006#
Andrea.
a_abdi406
Set the Locale to CultureInfo.CurrentCulture immediatelly after creating DataSet or DataTable and then you can select rows from table in this way:
DataRow[] rows = myTable.Select(string.Format("[DateColumnName] >= '{0}' and ("[DateColumnName] <= '{1}'", dateFrom, dateTo));
What is happening here is that DateTime values dateFrom and dateTo are converted to string but the format of date is the same as one used for storring dates in myTable just because Locale is CurrentCulture.
Leadorn
Could you provide more details on the exceptions that are thrown
-Tom Meschter
Software Dev, Visual C# IDE
baron5038
Which line throws the exception
or
-Tom Meschter
Software Dev, Visual C# IDE
GDigrego
String was not recognized as a valid DateTime.
mig16