当我执行应用程序时,应用程序运行..。然后,当我点击按钮,我得到了错误
SqlDateTime溢出必须在1/1/1753 12:00上午12:00至12/31/9999 11:59:59下午
我不知道该如何解决这个问题,因为互联网上的大多数解决方案似乎对我不起作用。这是SQL方面的东西吗?
private void button1_Click(object sender, EventArgs e)
{
SqlConnection sqlcn1 = new SqlConnection("My Connection String");
sqlcn1.Open();
//Stored Procedure
SqlCommand sqlcmddel = new SqlCommand("My_Stored_Procedure", sqlcn1);
sqlcmddel.CommandType = CommandType.StoredProcedure;
sqlcmddel.ExecuteNonQuery();
sqlcn1 = new SqlConnection("My Connection String");
sqlcn1.Open();
foreach (DataGridViewRow row in dataGridView1.Rows)
{
SqlCommand sqlcmdins = new SqlCommand("My_Stored_Procedure", sqlcn1);
sqlcmdins.CommandType = CommandType.StoredProcedure;
//Stored Procedure
sqlcmdins.Parameters.Add("@sugnum", SqlDbType.Int).Value = Convert.ToInt64 (row.Cells[0].Value);
sqlcmdins.Parameters.Add("@sugtype", SqlDbType.NVarChar, 50).Value = Convert.ToString(row.Cells[1].Value);
sqlcmdins.Parameters.Add("@buyerid", SqlDbType.NVarChar, 50).Value = Convert.ToString (row.Cells[2].Value);
sqlcmdins.Parameters.Add("@duedate", SqlDbType.DateTime).Value = Convert.ToDateTime (row.Cells[3].Value);
sqlcmdins.Parameters.Add("@xrelqty", SqlDbType.Float).Value = Convert.ToDouble (row.Cells[4].Value);
sqlcmdins.Parameters.Add("@purchasingfactor", SqlDbType.Float).Value = Convert.ToDouble (row.Cells[5].Value);
}
}发布于 2017-07-20 14:42:09
在SQL端将数据类型更改为datetime2 (很抱歉,简短的回答,不能发表评论)
发布于 2017-07-20 15:21:50
尝试传递字符串值,参数将计算出正确的数据类型示例qlcmdins.Parameters.Add("@duedate", row.Cells[3].Value.ToString())。
https://stackoverflow.com/questions/45217803
复制相似问题