conversion failed when converting date and or time from character string

Last Reply on Nov 21, 2012 10:58 PM By Mudassar

Posted on Nov 20, 2012 06:43 AM

i want to search record with dropdown list and text box 

i have fields in dropdown like 

1.Orthopedics

2.Clinic

3.Pharmacy

4.ENT

when i select one field and type date in text box i want a list of record submitted on this date with the specific field 

 

I Tried This 

 

protected void Button1_Click(object sender, EventArgs e)
        {

        
            DateTime date1 = Convert.ToDateTime(TextBox1.Text);
            con.Open();
            SqlCommand cmd = new SqlCommand("SELECT * FROM KSMCemp_data WHERE Exp_Date='" + date1 + "'",con);
         
           
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            da.Fill(ds);
            GridView1.DataSource = ds;
            GridView1.DataBind();
          

          
        }
Giving this error 
conversion failed when converting date and/or time from character string

 

Posted on Nov 21, 2012 10:58 PM

In your query there is no '00' so it is not possible for this query to throw error. Post a screenshot of the exception for more details