将varchar数据类型转换为日期时间数据类型会导致超出范围的值。请解决我的问题 [英] The conversion of a varchar data type to a datetime data type resulted in an out-of-range value. pls solve my problem

查看:103
本文介绍了将varchar数据类型转换为日期时间数据类型会导致超出范围的值。请解决我的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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();
        }

推荐答案

您再次发布了同样的问题。我已经为您解决了问题。



在原始问题中查看我的解决方案:将varchar数据类型转换为日期时间数据类型导致超出范围值。 [ ^ ]
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.[^]


cmd.CommandText = "INSERT INTO person (birthdate) VALUES(@date)";
            cmd.Parameters.Add(new SqlParameter("@date", dateTimePicker.Value.Date));





这样做而不是





do this instead of

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);


这篇关于将varchar数据类型转换为日期时间数据类型会导致超出范围的值。请解决我的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆