使用vb.net中的参数插入SQLite数据库

时间:2012-11-20 16:41:41

标签: vb.net parameters sqlite

我想将列表项插入带有参数的SQLite3数据库,但它不起作用..我甚至没有得到任何错误。

这是我的代码:

strSQL = "insert into tbltrans2 (transid, flddate, itemcode, itemname, qty, price, total, btw, btwper) values ( ?,?,?,?,?,?,?,?,?)"
Using cn As New SQLiteConnection("Data Source=" + Application.StartupPath + "\POS.s3db; Version=3;"), _
    cmd As New SQLiteCommand(strSQL, cn)

    cmd.Parameters.Add("?", DbType.String).Value = txtTransId.Text
    cmd.Parameters.Add("?", DbType.Date).Value = txtDate.Text
    cmd.Parameters.Add("?", DbType.Double)
    cmd.Parameters.Add("?", DbType.Double)
    cmd.Parameters.Add("?", DbType.Double)
    cmd.Parameters.Add("?", DbType.Double)
    cmd.Parameters.Add("?", DbType.Double)
    cmd.Parameters.Add("?", DbType.Double)
    cmd.Parameters.Add("?", DbType.Double)

    cn.Open()
    For Each ls As ListViewItem In ListItems.Items
        cmd.Parameters(2).Value = ls.Tag
        cmd.Parameters(3).Value = ls.SubItems(0).Text
        cmd.Parameters(4).Value = (ls.SubItems(1).Text)
        cmd.Parameters(5).Value = (ls.SubItems(2).Text)
        cmd.Parameters(6).Value = (ls.SubItems(3).Text)
        cmd.Parameters(7).Value = (Double.Parse(ls.SubItems(5).Text) / 100) * (Double.Parse(ls.SubItems(3).Text)).ToString("#,##0.00")
        cmd.Parameters(8).Value = Double.Parse(ls.SubItems(5).Text)

        cmd.ExecuteNonQuery()
        MsgBox(strSQL)
     Next ls
     cn.Close()
 End Using

1 个答案:

答案 0 :(得分:0)

你可以这样做......只是擦除值?...然后在cmd.parameters.add。(Dbtype.String).value = txtTransId.Text ....只需将它放在文本全部值..

strSQL = "insert into tbltrans2 (transid, flddate, itemcode, itemname, qty, price, total, btw, btwper)"
Using cn As New SQLiteConnection("Data Source=" + Application.StartupPath + "\POS.s3db; Version=3;"), _
    cmd As New SQLiteCommand(strSQL, cn)

    cmd.Parameters.Add( DbType.String).Value = txtTransId.Text
    cmd.Parameters.Add( DbType.Date).Value = txtDate.Text
    cmd.Parameters.Add( DbType.Double).Value = "The TEXT HERE"
    cmd.Parameters.Add( DbType.Double).Value = "The TEXT HERE"
    cmd.Parameters.Add( DbType.Double).Value = "The TEXT HERE"
    cmd.Parameters.Add( DbType.Double).Value = "The TEXT HERE"
    cmd.Parameters.Add( DbType.Double).Value = "The TEXT HERE"
    cmd.Parameters.Add( DbType.Double).Value = "The TEXT HERE"
    cmd.Parameters.Add(DbType.Double).Value = "The TEXT HERE"

    cn.Open()
    For Each ls As ListViewItem In ListItems.Items
        cmd.Parameters(2).Value = ls.Tag
        cmd.Parameters(3).Value = ls.SubItems(0).Text
        cmd.Parameters(4).Value = (ls.SubItems(1).Text)
        cmd.Parameters(5).Value = (ls.SubItems(2).Text)
        cmd.Parameters(6).Value = (ls.SubItems(3).Text)
        cmd.Parameters(7).Value = (Double.Parse(ls.SubItems(5).Text) / 100) * (Double.Parse(ls.SubItems(3).Text)).ToString("#,##0.00")
        cmd.Parameters(8).Value = Double.Parse(ls.SubItems(5).Text)

        cmd.ExecuteNonQuery()
        MsgBox(strSQL)
     Next ls
     cn.Close()
 End Using