0

我想将列表项插入带有参数的 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
4

1 回答 1

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
于 2013-03-15T00:37:33.720 回答