Home Articles

将数据表数据绑定到C#中的checkedListBox

Asked
Viewed 1470 times
0

如何将数据表绑定到checkedlistbox?我尝试使用此代码但数据源属性未初始化

CheckedListBox cb = new CheckedListBox();
checkedListBox1.DataBindings = dbFunctions.getTable("pr_fetchLocal'" + editypeId + "'");

((ListBox)cb).DataSource = dtfetchSub;
((ListBox)cb).DisplayMember = "name";
((ListBox)cb).ValueMember = "Id";
cb.Show();

1 Answer

  • 0

    只需将表绑定到DataSource属性即可 .

    cd.DataSource = dbFunctions.getTable("pr_fetchLocal'" + editypeId + "'");
    

    似乎editTypeId是一个字符串(我猜这是基于'')所以这是SQL注入的opend . 您可能想要研究如何在ADO.NET中传递参数:)

Related