Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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..


C#
 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

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.
 
Share this answer
 
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.
 
Share this answer
 
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:
C#
DateTime.Parse(TextBox1.Text).ToString("yyyy-MM-dd hh:mm:ss");


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

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