2012-05-24 170 views
0

我有這個疑問的作品不錯插入aaccess DB數據,但我現在試圖插入一個sqllite3分貝,但其使用相同的查詢插入查詢

Imports System.Data.Odbc 

Public Class Form1 
Public con As New OdbcConnection("Dsn=SQLite3 Datasource;database=C:\Users\pcampos\Desktop\spiceworks_prod.db;stepapi=0;syncpragma=NORMAL;notxn=0;timeout=100000;shortnames=0;longnames=0;nocreat=0;nowchar=0;fksupport=0;oemcp=0;bigint=0") 

Dim query As String = "INSERT INTO INSERT INTO tickets(id, summary, status) VALUES(@id,@summary,@status)" 


      con.Close() 
      con.Open() 
      Using cmd As New OdbcCommand(query, con) 

       cmd.Parameters.AddWithValue("@id", OdbcType.VarChar).Value = test 
       cmd.Parameters.AddWithValue("@sumamry", OdbcType.VarChar).Value = "ola ola ola" 
       cmd.Parameters.AddWithValue("@staus", OdbcType.VarChar).Value = "close" 


       Dim x As Integer = cmd.ExecuteNonQuery() 
       MsgBox(x) 


       If x < 1 Then 
        MessageBox.Show("Erro ao inserir", My.Application.Info.Title, MessageBoxButtons.OK, MessageBoxIcon.Error) 
       Else 
        MessageBox.Show("Registo1 inserido com sucesso!", My.Application.Info.Title, MessageBoxButtons.OK, MessageBoxIcon.Information) 

       End If 
      End Using 

End Class 

回答

1

麻煩IM該查詢不是有效的SQL。它應該是這樣的:

Dim query As String = "INSERT INTO tickets (id, summary, status) VALUES(@id, @summary, @status)" 

的圖,詳細的關鍵詞在SQL INSERT語句的順序查看SQLite Insert Query Manual。 SQL會在其他基於SQL的系統上出錯,而​​不僅僅是SQLite。只是覺得我會連接到該手冊頁,因爲它非常有用。