Click here to Skip to main content
12,948,105 members (79,432 online)
Rate this:
Please Sign up or sign in to vote.
i want to search record using dropdown and text box
the data type is DateTime
in date column its saving as 28/11/2012 12:45:08 full date and time
i am using this code for searching record its working server but not on client systems..

 protected void Button2_Click(object sender, EventArgs e)
        SqlCommand cmd = new SqlCommand("SELECT * FROM Transactions WHERE report_type = @report_type AND " + "[R_date] >= @date_t_s and [R_date] < @date_t_e");
        cmd.Connection = con;
        cmd.Parameters.Add("@report_type", SqlDbType.NVarChar).Value = DropDownList1.SelectedValue;
        cmd.Parameters.Add("@date_t_s", SqlDbType.DateTime).Value = DateTime.Parse(TextBox1.Text);
        cmd.Parameters.Add("@date_t_e", SqlDbType.DateTime).Value = DateTime.Parse(TextBox1.Text).AddDays(1);
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        GridView1.DataSource = ds;
Posted 1-Dec-12 1:34am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Probably, the problem is to do with the culture being used by the client - if they do not enter the date in the format expected by your servers Culture setting, then the date passed to your query will be wrong, or cause a exception when you try to parse it.

You need to either access the clients date setting and parse according to that, or use a control that returns you a DataTime value instead of a string.
Rate this: bad
Please Sign up or sign in to vote.

Solution 4

select convert(varchar(10), Column_name, 103) as ShortDate from Table_name
then you get only date part from your column and if you provide your client a ajax calender tool then they can easily pick the date and that is matched with your requirement then you can easily use between query.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2


your client system time format may be varied with your server system time format. So, after parsing the textbox value to dateTime you should apply your SQL date time format

DateTime.Parse(TextBox1.Text).ToString("yyyy-MM-dd hh:mm:ss");

Rate this: bad
Please Sign up or sign in to vote.

Solution 3

Kindly convert data formate in "yyyy/MM/dd hh:ss:tt" and it should work.
also check for culture

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

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 5,344
CHill60 3,275
Maciej Los 2,703
Jochen Arndt 1,935
ppolymorphe 1,795

Advertise | Privacy | Mobile
Web02 | 2.8.170524.1 | Last Updated 2 Dec 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100