0
SQLite的外鍵支持下面這個教程http://www.sqlite.org/foreignkeys.html我需要3個表數據庫但我不能修復一個關於「SQL邏輯錯誤....近洋」啓用VB的淨
Private Sub CreateDataBase()
Dim conn = New SQLiteConnection("Data Source=MyDataBase.sqlite;Version=3")
Try
Using (conn)
conn.Open()
'3 Tables I need to create
Dim mainTable = "CREATE TABLE IF NOT EXISTS users (userID INTEGER PRIMARY KEY, name VARCHAR(20))"
Dim tableA = "CREATE TABLE IF NOT EXISTS tableA (ItemA VARCHAR(20), user INTEGER) FOREIGN KEY(user) REFERENCES users (userID)"
Dim tableB = "CREATE TABLE IF NOT EXISTS tableB (ItemB VARCHAR(20), user INTEGER) FOREIGN KEY(user) REFERENCES users (userID)"
Dim cmdConexion As SQLiteCommand = New SQLiteCommand(mainTable, conn)
'Try for the mainTable
Try
cmdConexion.ExecuteNonQuery()
Catch ex As Exception
MsgBox(ex.ToString())
End Try
'Set and Try for tableA
cmdConexion.CommandText = tableA
Try
cmdConexion.ExecuteNonQuery()
Catch ex As Exception
MsgBox(ex.ToString())
End Try
'Set and Try for tableB
cmdConexion.CommandText = tableB
Try
cmdConexion.ExecuteNonQuery()
Catch ex As Exception
MsgBox(ex.ToString())
End Try
End Using
Catch ex As Exception
MsgBox(ex.ToString())
End Try
End Sub
消息
相同的代碼只適用於mainTable。
我用一條線tryed像
Pragma("foreign_keys") = 1
甚至
cmdConexion.CommandText = "PRAGMA foreign_keys = ON"
但還是我不能修復錯誤。
SQL行或Pragma上的錯誤在哪裏?
注意: 另外,是否有另一種方法來執行相同的TryCatch的SQL創建表或更好的嘗試 - 捕獲每個表?
對!這兩個解決方案都有效我的錯誤是一個「)」不合適。感謝您的提示 – fedeteka