?
Solved

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

Posted on 2010-11-25
2
Medium Priority
?
1,473 Views
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.Parameters.Add(p1)

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

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

        MsgBox(cmd.CommandText)
        cnn.Open()
        cmd.ExecuteNonQuery()

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

Open in new window

0
Comment
Question by:Jedeye
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 5

Expert Comment

by:buraksarica
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)" _


here.

it may be about these.
0
 
LVL 14

Accepted Solution

by:
systan earned 2000 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
            sc.ExecuteNonQuery()
            sc.Parameters.Clear()
            sr.Close()
            sc.Dispose()
        End If
    End Sub

Open in new window

0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
If you are a mobile app developer and especially develop hybrid mobile apps then these 4 mistakes you must avoid for hybrid app development to be the more genuine app developer.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

719 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