嗨我有一個數據庫有幾個字段,我只想將信息插入其中兩個。從excel中提供這些信息;從Excel工作表連接到Access數據庫 - 語法錯誤
Sub testing()
On Error GoTo errorhandler
'
' testing Macro
'
' Keyboard Shortcut: Ctrl+d
'
Dim cn As Object
Dim rs As Object
Dim strSql As String
Dim strConnection As String
Set cn = CreateObject("ADODB.Connection")
strConnection = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Database\Path\Here\Database.accdb"
strSql = "INSERT INTO Clients (FirstName, Initial Contact) VALUES ('Joe Sixpack', 12/1/2015);"
cn.Open strConnection
Set rs = cn.Execute(strSql)
' rs.Close
cn.Close
Exit Sub
errorhandler:
MsgBox (Err.Number & " " & Err.Description)
End Sub
我收到一條錯誤消息「INSERT INTO語句中的語法錯誤」。但我看看W3學校的SQL文檔,我看到
INSERT INTO Customers (CustomerName, ContactName, Address, City, PostalCode, Country) VALUES ('Cardinal','Tom B. Erichsen','Skagen 21','Stavanger','4006','Norway');
所以語法看起來正確。我剛剛證實表格名稱也是正確的。那麼語法錯誤在哪裏?
語法錯誤是需要被包裹在方括號或反引號列名的空間。此外,日期需要用磅/標籤包裝。 – Parfait