在C#中以Windows窗体编辑更新删除ListBox [英] Edit update delete ListBox in windows form in c#

查看:115
本文介绍了在C#中以Windows窗体编辑更新删除ListBox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我有一个从数据库填充数据的列表框.如何编辑,更新和删除列表框中的项目并将其保存到数据库中.
请帮我解决一下...

谢谢,
Prasant

Hi All,

I have listbox in which data is populating from database.How will i edit,update and delete the items in the List box ans save it into the Database.
Please help me something on this ...

Thanks,
Prasant

推荐答案

http://www.dotnetperls.com/listbox [^ ]
Google [ ^ ]了解更多
http://www.dotnetperls.com/listbox[^]
Google[^] for more


执行以下操作..

1.使用存储过程/查询从数据库中获取数据表/数据集中的数据.
2.要在列表框中添加数据,请执行以下操作
Do the following..

1. take data in datatable/dataset from database using Stored Procedure/query.
2. To add data in list box do the following
foreach (DataRow row in yourdatatable.Rows)
{

     listbox1.Items.Add(row["column_name"].ToString());
}


或使用listbox1.datasource = yourdatatable

3.编写存储过程以编辑更新和删除,然后在任意位置调用它.
要从列表框中删除项目,可以使用listbox1.Items.Remove(ItemToRemove)或listbox1.Items.Clear()删除所有项目.


Or use listbox1.datasource=yourdatatable

3. Write Stored procedure to edit update and delete and call it wherever you want.
to remove items from listbox you can use listbox1.Items.Remove(ItemToRemove) or listbox1.Items.Clear() to remove all items.


这篇关于在C#中以Windows窗体编辑更新删除ListBox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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