Click here to Skip to main content
15,903,175 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
XML
The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.

The statement has been terminated.

 private void button1_Click(object sender, EventArgs e)
        {
            con.Open();
            cmd = new SqlCommand(@"INSERT INTO Login(Admin,Password,Age,Gender,Dateofbirth)VALUES('" + textBox1.Text + "','" + textBox2.Text + "','"+textBox3.Text+"','"+ Gender +"','"+dateTimePicker1.Value.ToString("dd/mm/yyyy hh:mm") +"')", con);
            cmd.ExecuteNonQuery();
            MessageBox.Show("data Registered successfully!");
            con.Close();
        }
Posted
Updated 7-Jul-14 19:02pm
v2
Comments
Member 10918596 8-Jul-14 1:02am    
above error came how to solve error...

You posted the same question again. I already gave you a solution for your problem.

See my solution in your original question: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.[^]
 
Share this answer
 
C#
cmd.CommandText = "INSERT INTO person (birthdate) VALUES(@date)";
            cmd.Parameters.Add(new SqlParameter("@date", dateTimePicker.Value.Date));


do this instead of

C#
cmd = new SqlCommand(@"INSERT INTO Login(Admin,Password,Age,Gender,Dateofbirth)VALUES('" + textBox1.Text + "','" + textBox2.Text + "','"+textBox3.Text+"','"+ Gender +"','"+dateTimePicker1.Value.ToString("dd/mm/yyyy hh:mm") +"')", con);
 
Share this answer
 
Comments
Member 10918596 8-Jul-14 1:10am    
same concept above mentioned.tell me the error..
Pravuprasad 8-Jul-14 1:22am    
cmd.Parameters.Add(new SqlParameter("@date",.....) its the different concept here.so this will omit the error . And plz don't post same question every day. just refer your old one.

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