【发布时间】:2016-02-17 17:14:33
【问题描述】:
我正在用 C# 编写 WinForms 代码,基本上有以下内容:
DateTime localDate = DateTime.UtcNow;
SqlConnection Conn = new SqlConnection("....[connection info]....");
Conn.Open();
SqlCommand sqlcomm = new SqlCommand("INSERT INTO dbo.Call VALUES(...., @Time,...);", Conn);
sqlcomm.Parameters.Add("@Time", SqlDbType.DateTime);
sqlcomm.Parameters["@Time"].Value = localDate;
Int32 o = sqlcomm.ExecuteNonQuery();
这会引发“When converting a string to DateTime, parse the string to take the date before putting each variable into the DateTime object.”的错误,据我所知,它认为localDate 变量是一个字符串,但如果我写入控制台localDate.GetType(),它会显示System.DateTime。
数据库中“@Time”的列设置为 DateTime,所以这不是问题。有什么想法吗?
【问题讨论】:
-
异常到底是在哪里抛出的?