Voor dat in te voeren in een sqlite db gebruik ik geparameteriseerde entry's, nu wil het lukken dat het niet lukt. Als ik de insert doe dan krijg ik de fout melding dat ie @table niet kan vinden.
Dit is wat er in het debug scherm komt
Als ik dan uit de functie gaat dan komt er het volgende bij (deze insert is via een andere functie)
De functie die ik gebruik: [code=vb] 'insert data, returns last inserted id
Public Function Insert(table As String, data As Dictionary(Of String, Object)) As Integer
Insert = -1
Try
If data.Count >= 1 Then
Using cmd As New SQLiteCommand("INSERT INTO @table (@colums)VALUES(@values);")
cmd.Parameters.AddWithValue("@table", table)
Dim columns As String = ""
Dim values As String = ""
For Each val As KeyValuePair(Of String, Object) In data
columns &= val.Key & ","
values &= "@" & val.Key & ","
cmd.Parameters.AddWithValue("@" & val.Key, val.Value)
Next
columns = columns.Substring(0, columns.Length - 1)
values = values.Substring(0, values.Length - 1)
cmd.Parameters.AddWithValue("@colums", columns)
cmd.Parameters.AddWithValue("@values", values)
columns = Nothing
values = Nothing
If bdebug Then SqlString(cmd)
Using conn As SQLiteConnection = New SQLiteConnection(db)
conn.OpenAsync()
Using trans As SQLiteTransaction = conn.BeginTransaction
cmd.Connection = conn
cmd.ExecuteNonQuery()
cmd.CommandText = "select last_insert_rowid();"
Insert = CInt(cmd.ExecuteScalar)
trans.Commit()
End Using
End Using
cmd.Parameters.Clear()
End Using
End If
Catch e As Exception
Throw New Exception(e.Message)
End Try
End Function[/code=vb]
Wat gaat er fout, is dat om dat er nog een @ overblijft of?
Dit is wat er in het debug scherm komt
code:
1
2
3
4
5
6
7
8
9
10
11
| ---------------- @table = [tblUser] (String) @UserName = [z603311] (String) @colums = [UserName] (String) @values = [@UserName] (String) INSERT INTO @table (@colums)VALUES(@values); ---------------- SQLite error (1): near "@table": syntax error Exception thrown: 'System.Data.SQLite.SQLiteException' in System.Data.SQLite.dll |
Als ik dan uit de functie gaat dan komt er het volgende bij (deze insert is via een andere functie)
code:
1
2
3
4
5
6
7
8
9
10
| Exception thrown: 'System.Exception' in Telemeter Indicator.exe ---------------- @uname = [z725831] (String) @message = [IMPORT_DB::ERR: SQL logic error or missing database near "@table": syntax error] (String) select last_insert_rowid(); Rows Updated: 29054 ---------------- |
De functie die ik gebruik: [code=vb] 'insert data, returns last inserted id
Public Function Insert(table As String, data As Dictionary(Of String, Object)) As Integer
Insert = -1
Try
If data.Count >= 1 Then
Using cmd As New SQLiteCommand("INSERT INTO @table (@colums)VALUES(@values);")
cmd.Parameters.AddWithValue("@table", table)
Dim columns As String = ""
Dim values As String = ""
For Each val As KeyValuePair(Of String, Object) In data
columns &= val.Key & ","
values &= "@" & val.Key & ","
cmd.Parameters.AddWithValue("@" & val.Key, val.Value)
Next
columns = columns.Substring(0, columns.Length - 1)
values = values.Substring(0, values.Length - 1)
cmd.Parameters.AddWithValue("@colums", columns)
cmd.Parameters.AddWithValue("@values", values)
columns = Nothing
values = Nothing
If bdebug Then SqlString(cmd)
Using conn As SQLiteConnection = New SQLiteConnection(db)
conn.OpenAsync()
Using trans As SQLiteTransaction = conn.BeginTransaction
cmd.Connection = conn
cmd.ExecuteNonQuery()
cmd.CommandText = "select last_insert_rowid();"
Insert = CInt(cmd.ExecuteScalar)
trans.Commit()
End Using
End Using
cmd.Parameters.Clear()
End Using
End If
Catch e As Exception
Throw New Exception(e.Message)
End Try
End Function[/code=vb]
Wat gaat er fout, is dat om dat er nog een @ overblijft of?
Al wat ik aanraak werk niet meer zoals het hoort. Damic houd niet van zijn verjaardag