将数据绑定到CheckedListBox [英] Binding Data to a CheckedListBox

查看:134
本文介绍了将数据绑定到CheckedListBox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我想知道如何从CheckedListBox数据库中的表中查看数据.

给定三个表:
users:ID,用户名,密码
privileges:pri_num,特权
user_privileges:id,pri_num

user_privileges提供了连接机制.

我想查看给定用户的可用特权列表,并将选中的(启用的)特权保存到数据库中.问题,无论您尝试了什么,都已经在此处了 [ d_adapter = new SqlDataAdapter(query,connect);<br /> d_set = new DataSet();<br /> d_adapter.Fill(d_set,query);<br /> for (int i = 0; i< this.mcode.d_set.Tables[0].Rows.Count; i++)<br /> {<br /> this.u_privleges_chListBox.Items.Add(this.mcode.d_set.Tables[this.mcode.query].Rows[i][1].ToString());<br /> }<br /> }</pre><br />


但是我不知道如何使checkedlistbox中项目的值是特权数(Pri_num),并且我想通过User_privileges中的用户值(Pri_num)在数据库中保存用户的checked(enable)

谢谢您的配合


您只检索了特权列表,但未检索到分配给特定用户的特权.

您将需要 两者 加载特权和user_privileges列表(由当前用户过滤).如果这是一组新的权限,则需要存储特权的ID,而不仅仅是文本.

请检查我链接到的示例应用程序.您正在寻找的信息已经存在.

干杯.


Hello,

I want to know how to view data from a table in a database in CheckedListBox.

Given three tables:
users: id, username, password
privileges: pri_num, privilege
user_privileges: id, pri_num

user_privileges provides the mechanism for joining.

I would like to view the list of available privileges for a given user and save the checked (enabled) privileges to the database.

I think the solution to your entire question, regardless of what you''ve tried, is already here[


this is my tried to display the data in checkedlistbox from database(SQL Server 2005 enterprise)
look this code

<br />
<pre><br />
public void Privileges()<br />
 {<br />
    this.mcode.query = "select Pri_num,Pri_name from Privileges";<br />
    d_adapter = new SqlDataAdapter(query,connect);<br />
    d_set = new DataSet();<br />
    d_adapter.Fill(d_set,query);<br />
    for (int i = 0; i< this.mcode.d_set.Tables[0].Rows.Count; i++)<br />
    {<br />
     this.u_privleges_chListBox.Items.Add(this.mcode.d_set.Tables[this.mcode.query].Rows[i][1].ToString());<br />
    }<br />
 }</pre><br />


but i don''t know how to make the value of the items in checkedlistbox is the privileges number (Pri_num)and i would like to save the checked(enable) for the user in the database by its value (Pri_num) in User_privileges

thank you for your cooperation


You have only retrieved the list of privileges, but not their assignment to a specific user.

You will need to load both the list of privileges and user_privileges (filtered by your current user). If this is a new set of permissions, you need to store the id of the privileges and not just the text.

Please check out the sample application I linked to. The information you are looking for is already there.

Cheers.


这篇关于将数据绑定到CheckedListBox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆