0

我有这个查询可以很好地在 aaccess db 中插入数据,但现在我试图在 sqllite3 db 上插入,但我无法使用相同的查询

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
4

1 回答 1

1

该查询不是有效的 SQL。它应该是这样的:

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

请参阅SQLite 插入查询手册以获取详细说明 SQL 插入语句中关键字顺序的图表。SQL 在其他基于 SQL 的系统上会出错,而不仅仅是 SQLite。只是想我会链接到该手册页,因为它非常有用。

于 2012-05-27T23:35:15.943 回答