如何在窗口应用程序的清单列表框中绑定数据 [英] how to bind data in checkedlistbox in window application
本文介绍了如何在窗口应用程序的清单列表框中绑定数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的代码,但是...正在工作.....?
Here is my code but...working.....?
SqlDataAdapter da = new SqlDataAdapter("SELECT NAME AC_CODE FROM AccountM where compcode='" + Compcls.Gcomp_cd + "'", con);
DataSet ds = new DataSet();
da.Fill(ds, "AccountM ");
checkedListBox1.DataSource = ds;
checkedListBox1.SelectedValue = "AC_CODE";
checkedListBox1.SelectedItem = "NAME";
}
我想要显示显示成员(名称);
和值成员(AC_COde);
任何伙伴都可以告诉...如何从数据库中绑定清单列表中的数据吗?
感谢进阶
lakhan
I want show display member (Name);
and value member (AC_COde);
Can any buddy tell ....how to bind data in checkedlistbox from database?
Thanks in advanced
lakhan
推荐答案
请参阅以下内容:
从数据库表读取数据将其添加到ListBox
[ ^ ]
将数据从数据库填充到列表框 [
Refer these:
Read data from database table add it to a ListBox
[^]
Fill data from Database to ListBox[^]
hope it helps :)
首先,不要将值直接连接到SQL语句.请改用参数,请参见: SqlParameter [ DisplayMember [ ValueMember [ ^ ]属性来定义绑定应使用的字段.
加法:
我认为您的SQL语句中应该有一个逗号.试试:
First, do not concatenate values directly to an SQL statement. Use parameters instead, see: SqlParameter[^].
About the binding use the DisplayMember[^] and ValueMember[^] properties to define the fields your binding should use.
Addition:
I think you should have a comma in your SQL statement. Try:
SqlDataAdapter da = new SqlDataAdapter("SELECT NAME, AC_CODE FROM AccountM where compcode='" + Compcls.Gcomp_cd + "'", con);
并记住在查询中添加参数:
And remember to add parameter to your query:
SqlDataAdapter da = new SqlDataAdapter("SELECT NAME, AC_CODE FROM AccountM where compcode=@compcode", con);
...
检查此博客
http://msdn.microsoft.com/en-us/library/system. windows.forms.checkedlistbox.aspx [ ^ ]
--NDK
check this blog
http://msdn.microsoft.com/en-us/library/system.windows.forms.checkedlistbox.aspx[^]
--NDK
这篇关于如何在窗口应用程序的清单列表框中绑定数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文