2010-03-05 101 views
0

當我嘗試執行下面的代碼時,出現以下錯誤。我添加了我傳遞的SQL字符串。我錯過了什麼?執行SQL時出錯

錯誤:

Syntax error (missing operator) in query expression 'TOURID = 25e5eed3-ea84-4c30-a660-2c880253da60'

我的查詢,

DELETE * FROM TOURS WHERE TOURID = 25e5eed3-ea84-4c30-a660-2c880253da60; 

我的代碼,

Dim connectionString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\_Development\Data\filename.accdb;Persist Security Info=False;" 
Dim DBConnection As New System.Data.OleDb.OleDbConnection(connectionString) 
Try 
    DBConnection .Open() 
    Dim cmd As New System.Data.OleDb.OleDbCommand(sql, DBConnection) 
    Dim sqlAdapterTOURS As New System.Data.OleDb.OleDbDataAdapter(cmd) 
    cmd.CommandType = CommandType.Text 
    cmd.ExecuteNonQuery() 
Catch ex As Exception 
    MessageBox.Show(ex.Message) 
Finally 
    DBConnection .Close() 
End Try 

回答

5

與GUIDS工作時,這樣你需要使用引號:

DELETE * 
FROM TOURS 
WHERE TOURID = '25e5eed3-ea84-4c30-a660-2c880253da60'; 
3

你的值應該用單引號括起來,就像這樣:

DELETE * FROM TOURS WHERE TOURID = '25e5eed3-ea84-4c30-a660-2c880253da60'; 
1

猜想:你的GUID類型條目應該被引用,也許?:

DELETE FROM TOURS WHERE TOURID = '25e5eed3-ea84-4c30-a660-2c880253da60' 
1

訪問/噴氣/ ACE不非常GUID友好。邁克爾·卡普蘭前寫了一篇關於這個多年:

Replication and GUIDs, the Good, the Bad, and the Ugly

根據上下文,您可能需要使用VBA函數與GUID的工作,即StringFromGUID()和GUIDFromString()。不過,我不確定你在SQL上下文中究竟需要做什麼。我知道你不能在兩個GUID字段之間進行連接(你必須使用隱式連接,也就是使用WHERE子句)。