I am trying to delete multiple entries from an SQLite database.
This is the code I am using
Public Function RemoveUsers(_users As List(Of User)) As Integer
Using conn As New SQLiteConnection(connectionString)
Dim removeUserQuery As String = "DELETE FROM Users WHERE userId IN (@userIds)"
Dim cmd As New SQLiteCommand(removeUserQuery, conn)
Dim listOfIds As New List(Of Integer)
For Each user As User In _users
listOfIds.Add(user.UserID)
Next
cmd.Parameters.AddWithValue("@userIds", String.Join(",", listOfIds))
Console.WriteLine(cmd.CommandText)
conn.Open()
Dim i As Integer = cmd.ExecuteNonQuery()
conn.Close()
Return i
End Using
End Function
The query will end up something like
DELETE FROM Users WHERE userId IN (2, 4, 5, 7, 9)
But I am always getting 0 rows affected. I tried it in DB Browser for SQLite and it worked. I assume its something to do with cmd.Parameters.AddWithValue() but I am not sure. Thanks in advance.