I have to add items to database, but need to make sure that one item is unique. what do i do here?
e.g lest say i need to add 100 rows of three columns each (school name idcard_num)
it is obvious that name should be unique here, while the rest can have duplicates
1 should i create a unique field , and spit out the database errors that will be thrown to the user?
2. should i check each items before adding?
i have this
Dim conn As New SQLiteConnection("Data Source=" & DBPath)
conn.Open()
Dim cmd As New SQLiteCommand(conn)
Dim mytransaction As SQLiteTransaction = conn.BeginTransaction()
Try
For i = 0 To UBound(oCourses)
cmd = New SQLiteCommand("INSERT INTO courses ([code]," & _
"[title],[unit]) VALUES (@code,@title,@unit)", conn)
cmd.Parameters.AddWithValue("@code", oCourses(i).Code)
cmd.Parameters.AddWithValue("@title", oCourses(i).Title)
cmd.Parameters.AddWithValue("@unit", oCourses(i).Unit)
cmd.ExecuteNonQuery()
Next
mytransaction.Commit()
Return Nothing
Catch ex As Exception
mytransaction.Rollback()
Debug.Print(ex.Message)
Return ex.Message
Finally
cmd.Dispose()
conn.Dispose()
mytransaction.Dispose()
End Try