Click here to Skip to main content
15,892,517 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
plz solve my problem i have get This error message

< Implicit conversion from data type varchar to varbinary is not allowed. Use the CONVERT function to run this query. >

I am using SQL SERVER Date datatype using for Datetimepicker (custum format)

plz help me for this problam

C#
private void button4_Click(object sender, EventArgs e)
       {

           Convert.ToDateTime(this.dateTimePicker1.Value).ToString("MM/dd/YYYY");
           textBox1.Text = dateTimePicker1.Text;
       }

       private void button1_Click(object sender, EventArgs e)
       {
           try
           {
              
               con.Open();
                   
               String q = "insert into Development_Detal values('" + Ename.Text + "','" + UserPass.Text + "','" + EmpID.Text + "','" + address.Text + "','" + emaill.Text + "','" +textBox1.Text+"','" + mobNo.Text + "','" + city.Text + "' )";

               SqlCommand cmd = new SqlCommand(q, con);
              

               if ((Ename.Text == "") || (UserPass.Text == "") || (EmpID.Text == "") || (address.Text == "") || (mobNo.Text == "") || (city.Text == ""))
               {
                   MessageBox.Show("Must be fill all data ");
               }
               else
               {
                   cmd.ExecuteNonQuery();
                   MessageBox.Show("Employee Registration Successfully");
               }
           }

               catch(Exception ex)
               {
                   MessageBox.Show(ex.Message);
               }
           finally
           {
               con.Close();
           }


         }


Thanks in advance
Posted
Updated 19-Feb-13 23:14pm
v3

As the error suggests varchar cannot be converted to varbinary.
You are sending varchar text to the query.

Either use the Convert command on the database side

OR


instead of using +textBox1.Text+" directly in query, use
C#
Convert.ToDateTime(textBox1.Text)
 
Share this answer
 
As the error suggests varchar cannot be converted to varbinary.
You are sending varchar text to the query.

Either use the Convert command on the database side[^]

OR


instead of using +textBox1.Text+" directly in query, use
C#
Convert.ToDateTime(textBox1.Text)
 
Share this answer
 
Comments
Syed Shahabuddin 20-Feb-13 5:46am    
Thanks sir

but now i get erorr this messg "String was not recognized as a valid DateTime"
how to solve

how to String recognized??
Shubh Agrahari 20-Feb-13 6:07am    
its formatting problem...use correct for of your date like dd/mm/yyyy
Syed Shahabuddin 21-Feb-13 1:21am    
Thanks sir

now its showing error " Conversion Failed when converting date/or time from charecter string" i already change custum in properties window plz solve this
Thanks
Syed Shahabuddin 21-Feb-13 5:59am    
Thanks all

I got solution :)
Shubh Agrahari 21-Feb-13 7:44am    
ya its our pleasure..........
Hi
The lines:

Convert.ToDateTime(this.dateTimePicker1.Value).ToString("MM/dd/YYYY");


will not even allow you to compile. It's because dateTimePicker1.Value will return a datetime datatype and it will give you the error "Cannot implicitly conversion.

you have two options two store the value of dateTimePicker1 in a variable.

1. store it as string type.
string date;
date = dateTimePicker1.Value.ToString("yyyy/MM/dd");
OR

2. store it as datetime type.
DateTime date;
date = dateTimePicker1.Value;

and then you can set these with text box control like( textBox1.Text =date;) and set into sql query like('"+Date+"')

Thanks

There are various ways to save and retrieve this in a database.

Happy to Help....Thanks
 
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