1

我正在尝试学习如何在我的 VB.net 程序中使用 MS Access。我正在练习学习如何使用 INSERT INTO 语句,但我不断收到错误消息。

这是我的代码:

Imports System.Data.OleDb

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim myConnection As OleDbConnection
    Dim DBpath As String = "C:\Documents and Settings\nordeen1\Desktop\Test.mdb"
    Dim sConnectionString As String = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" & DBpath & ";Persist Security Info=True"
    myConnection = New OleDbConnection(sConnectionString)
    myConnection.Open()
    Dim SQLstr As String
    SQLstr = "INSERT INTO Test (Text, [Date], Number) VALUES ('testing', #2/6/1990#, 5)"
    Dim cmd As New OleDbCommand(SQLstr, myConnection)
    cmd.ExecuteNonQuery()
End Sub
End Class

我收到此错误“OleDbException 未处理。INSERT INTO 语句中的语法错误。” 在cmd.ExecuteNonQuery()

任何建议都非常感谢!谢谢!

4

2 回答 2

2

TEXT并且NUMBER也被保留,因此它们应该被分隔,

SQLstr = "INSERT INTO Test ([Text], [Date], [Number]) VALUES ('testing', #2/6/1990#, 5)"
于 2013-03-07T16:30:18.193 回答
2

用于CDATE您的日期:

   "INSERT INTO Test ([Text], [Date], [Number]) 
              VALUES ('testing',  CDATE('1990-06-02 00:00:00'), 5)"
于 2013-03-07T16:32:29.473 回答