我收到错误“将 varchar 数据类型转换为 datetime 数据类型导致值超出范围。 ”在执行 sql 命令时。日期时间的输入是“ 10/24/2013 06:25:30 PM ” //C#代码
string sa1 = dateTimePicker1.Value.ToString("MM/dd/yyyy");
string fr = textBox1.Text;
string dt = sa1 + " " + fr;
string to = textBox2.Text;
string dt1 = sa1 + " " + to;
DateTime tim = DateTime.ParseExact(dt.ToString(), "MM/dd/yyyy hh:mm:ss tt",System.Globalization.CultureInfo.InvariantCulture);
DateTime tim1 = DateTime.ParseExact(dt1.ToString(), "MM/dd/yyyy hh:mm:ss tt", System.Globalization.CultureInfo.InvariantCulture);
DateTime tim2 = Convert.ToDateTime(tim);
DateTime tim3 = Convert.ToDateTime(tim1);
dataGridView1.Rows.Clear();
SqlConnection con = new SqlConnection("Data Source=173.83.250.71,1433; Network Library=DBMSSOCN; Initial Catalog=paradigm;User Id=sa; password=Paradigm123");
con.Open();
SqlCommand cmd = new SqlCommand("insert into paradigm.dbo.driverotcalc ( emp_no, fro, too, purpose, totalhrs, entdate, amount) values('" + emp.ToString() + "','" + tim2.ToString() + "','" + tim3.ToString() + "','" + textBox3.Text + "','" + textBox4.Text + "','" + DateTime.Now + "','" + textBox5.Text + "')",con);
cmd.ExecuteNonQuery();
任何人都可以帮助我解决这个问题。