tags:

views:

193

answers:

2
A: 

My guess is that it's not recognizing your string as a valid datetime. The easiest way is to cast your strings to date using the appropriate SQL function.

Assuming it's SQL2005, you need to use CONVERT: http://msdn.microsoft.com/pt-br/library/ms187928.aspx

So it would look similar to this: TARIH>=CONVERT(smalldatetime,'" + datestart + " " + txtStartDateTime.Text + "',)

Where format is a number describing the format you're using for your your string, the link above has a list of valid formats.

Badaro
He's quierying a dataset, not the server, therefore this won't work.
ck
A: 

My guess would be that it isn't able to parse datestart + " " + txtStartDateTime.Text as a DateTime and therefore treats it as a String.

I would do this conversion before calling the Select method and then use DateTime.ToString() passing in datetime format that will work with DateTime.Parse (used internally by Select). e.g. if datestart is in the format "dd/MM/yyyy" and the input expected from txtStartDateTime is in format "HH:mm"

int hours = txtStartDateTime.Text.Substring(0,2);
int minutes = txtStartDateTime.Text.Substring(3,2);    
DateTime dtStart = new DateTime(Int32.Parse(datestart.Substring(5)), Int32.Parse(datestart.Substring(3,2)), Int32.Parse(datestart.Substring(0,2)), Int32.Parse(hours), Int32.Parse(minutes));

Then call

string dateFormat = "{0:s}";  
DataRow[] rows = dsChart.Tables[0].Select(string.Format("TARIH >= '{0}' AND TARIH <= '{1}'"), dtStart.ToString(dateFormat), dtEnd.ToString(dateFormat));
Andrew Corkery