Click here to Skip to main content
15,878,945 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi I have this error filtering date field.

This is the code.
C#
string filtro = "";

filtro += "and CAST(DATEDIFF(DAY, 0, FechaEntrada) AS DATETIME)  <=  ' " + Convert.ToDateTime(dateTimePicker1.Text) + " ' ";
DataSet ObjDataSet = new DataSet();
SqlDataAdapter objAdap = new SqlDataAdapter("SELECT * FROM lstEntrada WHERE (Estatus = 'ACTIVO')" + filtro + "  order by fechaentrada ", System.Configuration.ConfigurationSettings.AppSettings.Get("cadenaconnect"));
objAdap.Fill(ObjDataSet, "lstEntrada");
RepEntrada3 opt = new RepEntrada3();
opt.SetDataSource(ObjDataSet.Tables[0]);
crystalReportViewer1.ReportSource = opt
Posted
Updated 18-Nov-13 6:01am
v2
Comments
CHill60 18-Nov-13 12:43pm    
Things to look at ...
FechaEntrada ... how is it defined on the database
What is dateTimePicker1.Text set to?
I would also advise a space character at the beginning of filtro
Ganesh KP 18-Nov-13 12:57pm    
What is dateTimePicker1 here? Is it a DateTimePicker control or a textbox? If it is a datetime picker control, then I think u have to get the text by dateTimePicket1.Value.

What is the exception you are getting, paste the exception too and what line you are getting the exception? Paste the whole @durantvanzetty

1 solution

Hi again!!,

The solution was change the calendar settings of windows from dd/MM/yy to dd-MM-yy
 
Share this answer
 
Comments
CHill60 18-Nov-13 13:13pm    
That is NOT the best solution, you should contain all formatting requirements within your own code. What if you run this on a machine where you _cannot_ change the calendar settings?? Set the dateformat on your datetimepicker control, not on the PC.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900