1

I got a error 'Abort due to constraint violation column transid not unique' while inserting in a sqlite3 database. Here are my codes, can someone please help me?

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

1 Answer 1

1

Looks like there's a unique constraint on transid. That means you can't insert a row with a transid that already exists in the table.

Try entering a different transid, or setting transid as an auto-increment column, so you don't haver to enter it at all.

Sign up to request clarification or add additional context in comments.

1 Comment

The error message says that there is a unique constraint on it. Double check your database definition?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.