Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP ASP.NET Visual-Studio , +
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();
        da.Fill(ds);
        GridView1.DataSource = ds;
        GridView1.DataBind();
}
Posted 1-Dec-12 2:34am
Rate this: bad
good
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.
  Permalink  
Rate this: bad
good
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.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Hi,
 
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
 
EX:
DateTime.Parse(TextBox1.Text).ToString("yyyy-MM-dd hh:mm:ss");
 
--SJ
  Permalink  
Rate this: bad
good
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
  Permalink  

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



Advertise | Privacy | Mobile
Web01 | 2.8.1411022.1 | Last Updated 2 Dec 2012
Copyright © CodeProject, 1999-2014
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