Link to home
Start Free TrialLog in
Avatar of XK8ER
XK8ERFlag for United States of America

asked on

vb.net and using SQLite

Hello,
I just want to make sure that this is the right code for working with SQLite for fastest performance..

someone suggested me I should Use paramertized queries and to wrap connection and command also in Using block.. but how do I do that?

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Dim cons As New SQLite.SQLiteConnection
            Dim cmd As New SQLite.SQLiteCommand

            cons.ConnectionString = "Data Source=C:\data.s3db; Version=3"
            cons.Open()
            cmd = cons.CreateCommand()

            Using tx = cons.BeginTransaction()

                For i As Integer = 0 To 1000
                        cmd.CommandText = "INSERT INTO table1 VALUES('" & i & "')"
                        cmd.ExecuteNonQuery()
                Next

                tx.Commit()
            End Using

            cmd.Dispose()
            cons.Close()
    End Sub

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of jonnidip
jonnidip
Flag of Italy image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial