将日期插入sql数据库时出错?

时间:2017-06-16 20:30:24

标签: sql database vb.net oledb

我正在将记录插入数据库,但在“参数”日期中出现错误。任何想法都会很好。

myConnection.Open()
Dim sqlQry As String = "INSERT INTO MasterLabNumber (LabNumber, Location, Date)" + "VALUES(@LabNumber, @Location, @Date)"
Dim str As String
str = "SELECT * FROM MasterLabNumber WHERE (LabNumber = " & TextBox1.Text & ")"
Dim d As System.DateTime = DateTime.Now.ToString("yyyy/MM/dd")
Dim cmd As OleDbCommand = New OleDbCommand(sqlQry, myConnection)
cmd.Parameters.AddWithValue("@LabNumber", TextBox1.Text)
cmd.Parameters.AddWithValue("@Location", ComboBox1.Text)
cmd.Parameters.AddWithValue("@Date", d)

cmd.ExecuteNonQuery() <-- gets error here relating to adding the parameter date.

1 个答案:

答案 0 :(得分:2)

是的,原因const BLOCK_1: () = { mod inner { extern crate anymap; use self::anymap::AnyMap; } }; 是您在insert语句中使用的保留字。你需要使用Date

像下面那样逃避它
[]

您的插入声明应该变为

INSERT INTO MasterLabNumber (LabNumber, Location, [Date])