【问题标题】:Inserting combo box values to database?将组合框值插入数据库?
【发布时间】:2016-11-16 04:22:09
【问题描述】:

我现在使用“wilko”中的代码。但最后我想保存我得到了错误。

Dim dict As New Dictionary(Of String, Integer) Try dict.Add("Index 1", 1) dict.Add("Index 2", 2) dict.Add("Index 3", 3) dict.Add("Index 4", 4) cmbIndex.DataSource = New BindingSource(dict, Nothing) cmbIndex.DisplayMember = "Key" cmbIndex.ValueMember = "Value" Catch ex As Exception End Try .CommandText = "INSERT INTO tblMasterAksesJalanSKRD (kode_perus, nm_perusahaan, nm_pimpinan, alamat, volume, lokasi, masa_berlaku, tgl_exp, index, foto) VALUES (@a0,@a1,@a2,@a3,@a4,@a5,@a6,@a7,@a8,@a9)" .Parameters.Add("@a0", OleDbType.VarChar).Value = txtkode.Text .Parameters.Add("@a1", OleDbType.VarChar).Value = txtnmperus.Text .Parameters.Add("@a2", OleDbType.VarChar).Value = txtnmpim.Text .Parameters.Add("@a3", OleDbType.VarChar).Value = txtalamat.Text .Parameters.Add("@a4", OleDbType.VarChar).Value = txtvol.Text .Parameters.Add("@a5", OleDbType.VarChar).Value = txtlok.Text .Parameters.Add("@a6", OleDbType.VarChar).Value = txtmasber.Text .Parameters.Add("@a7", OleDbType.DBDate).Value = Date.Now .Parameters.Add("@a8", OleDbType.VarChar).Value = cmbIndex.SelectedValue ***(i still got error on this "Additional information: Syntax error in INSERT INTO statement.")*** .Parameters.Add("@a9", OleDbType.Binary).Value = IIf(pb1.Image IsNot Nothing, arrimage, DBNull.Value)

非常感谢

来自印度尼西亚的问候。

【问题讨论】:

    标签: .net vb.net visual-studio combobox binding


    【解决方案1】:

    您的绑定不会那样工作。尝试使用字典并创建新的绑定源:

        Dim dict As New Dictionary(Of String, Integer)
        dict.Add("Kota", 6000)
        dict.Add("Kabupaten", 5000)
        cmbIndex.DataSource = New BindingSource(dict, Nothing)
        cmbIndex.DisplayMember = "Key"
        cmbIndex.ValueMember = "Value"
    

    以下现在应该可以工作了:

        .Parameters.add("@a8", OleDbType.VarChar).Value = cmbIndex.SelectedValue
    

    【讨论】:

    • 请帮帮我,我的程序仍然有错误...非常感谢。
    猜你喜欢
    • 2021-09-03
    • 2014-08-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-29
    • 2021-08-14
    相关资源
    最近更新 更多