如何从表的单个列中的列表框或复选框列表中插入多个值? [英] How to Insert multiple values from a listbox or checkedlistbox in single column of a table ?
本文介绍了如何从表的单个列中的列表框或复选框列表中插入多个值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
用户应该能够从CheckedListBox或ListBox中选择多个值,并且当用户单击保存"时,记录应插入到表的单个列中.
我需要代码.
plz helppp
the user should be able to select multiple values from CheckedListBox or ListBox and when the user click ''Save'', the record should be inserted in a single column of a table.
I need code.
plz helppp
推荐答案
这是您要寻找的吗?
我创建了一个DataTable,添加了一个列,并在其中填充了一个遍历ListBox的所有Selected Items的for循环.
Is this what you are looking for?
I created a DataTable, added a single column and filled it with a for loop going through all the Selected Items of a ListBox.
DataTable dt = new DataTable();
dt.Columns.Add("Column1");
for (int i = 0; i < listBox1.SelectedItems.Count; i++)
{
dt.Rows.Add(listBox1.SelectedItems[i].ToString());
}
dataGridView.DataSource = dt;
您将行插入数据库表中,而不是列中.
您可以在(Checked)ListBox中循环选择选定的项目,并为每个项目插入一行,并在每一行中设置相同的列.我不知道那是不是你想要的.
尼克
You insert rows into a database table, not columns.
You can loop over the selected items in your (Checked)ListBox and insert a row for each item, setting the same column in each row. I don''t know if that is what you want.
Nick
这篇关于如何从表的单个列中的列表框或复选框列表中插入多个值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文