1
在sqlite3數據庫中插入時出現錯誤'由於約束違反列轉移不唯一'而中止。這裏是我的代碼,有人可以幫我嗎?在sqlite3數據庫中插入參數時在vb.net中出錯
Public Connection As SQLiteConnection
Public Function Getconnection() As SQLiteConnection
Connection = New SQLiteConnection
Connection.ConnectionString = "Data Source=" + Application.StartupPath + "\POS.s3db; Version=3;"
Connection.Open()
GetConnection = Connection
End Function
Using cmd As New SQLiteCommand(strSQL,Connection)
cmd.CommandType = CommandType.Text
strSQL = "insert into tbltrans2 (transid,itemcode,flddate,itemname,qty,price,total,btw,btwper) values ('@tid',@itemcode,'@date','@itemname','@qty','@price','@total','@btw',@btwper)"
cmd.Parameters.AddWithValue("tid", txtTransId.Text)
cmd.Parameters.AddWithValue("date", txtDate.Text)
''this is temp
For Each ls As ListViewItem In ListItems.Items
cmd.Parameters.AddWithValue("itemcode", ls.Tag)
cmd.Parameters.AddWithValue("itemname", ls.SubItems(0).Text)
cmd.Parameters.AddWithValue("qty", ls.SubItems(1).Text)
cmd.Parameters.AddWithValue("price", ls.SubItems(2).Text)
cmd.Parameters.AddWithValue("total", ls.SubItems(3).Text)
cmd.Parameters.AddWithValue("btw", (Double.Parse(ls.SubItems(5).Text)/100) * (Double.Parse(ls.SubItems(3).Text)).ToString("#,##0.00"))
cmd.Parameters.AddWithValue("btwper", Double.Parse(ls.SubItems(5).Text))
cmd.ExecuteNonQuery()
Next ls
End Using
但在我的數據庫中,transid不是唯一的字段。 –
錯誤消息表明它有一個唯一的約束。仔細檢查你的數據庫定義? – Andomar
我嘗試製作新表,但仍然沒有運氣 –