System.Data.SQLite - Parameterised query won't work

Posted on 2010-11-25
Last Modified: 2013-11-13
When I run the section of code below I get the error message "SQLite error Insufficient parameters supplied to the command"

Can anyone give me an indication of what I am doing wrong?
Private Sub test()
        Dim ConnectionString As String = "C:\Users\Des\Documents\Visual Studio 2008\Projects\QD-People\test1.dta"
        Dim cnn As New SQLite.SQLiteConnection()
        cnn.ConnectionString = "Data Source=" & ConnectionString & ";"
        Dim cmd As SQLite.SQLiteCommand
        cmd = cnn.CreateCommand
        Dim p1 As New SQLiteParameter("pTest")
        p1.Direction = ParameterDirection.Input
        p1.Value = #1/2/1948#

        'cmd.CommandText = "INSERT INTO tblSessions (Connection, StartTime) VALUES ('" _
        ' & ConnectionString & "'," & "(@test)" & ");"

        cmd.CommandText = "INSERT INTO tblSessions (Connection, StartTime) VALUES " _
         & "('" _
         & ConnectionString _
         & "'," _
         & "(@test)" _
         & ");"


    End Sub

Open in new window

Question by:Jedeye

Expert Comment

ID: 34212258
You are setting parameter before setting CommandText, it may be about that. Also, your parameter name here

Dim p1 As New SQLiteParameter("pTest")

doesn't match with

 & "(@test)" _


it may be about these.
LVL 14

Accepted Solution

systan earned 500 total points
ID: 34212923
use $ not @

code snippet;
Private Sub ZeroIncomeDate()

        Dim dt As DateTime = DateTime.Now

        Dim ddate As String = dt.ToShortDateString()

        Dim ss As String = "select dtime from dincome where dtime=$xddate"

        Dim sc As New SQLiteCommand(ss, mycon)

        sc.Parameters.Add("$xddate", DbType.String).Value = ddate

        Dim sr As SQLiteDataReader = sc.ExecuteReader

        If Not sr.HasRows Then

            ss = "insert into dincome(dtime,dcash,dpaper)values" & _

            "(" & _

            "$xdtime,$xdcash,$xdpaper" & _


            sc = New SQLiteCommand(ss, mycon)

            sc.Parameters.Add("$xdtime", DbType.String).Value = ddate

            sc.Parameters.Add("$xdcash", DbType.Decimal).Value = 0

            sc.Parameters.Add("$xdpaper", DbType.Decimal).Value = 0





        End If

    End Sub

Open in new window


Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Events in static methods 3 50
Base1 Encode/Decode 3 67
C# application error "Parameter Is Not Valid". 3 79
Web Form VB.Net  import CSV 4 24
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now