如何使用 SQLCE 在选中列表框中选择和显示具有多列的行?
我一直在遵循教程从表中选择行并将其显示在选中的列表框中。仅用一列即可正常工作。但是,我似乎无法弄清楚在选择多列时如何执行此操作。谷歌也不是很有帮助。
我需要显示库存中的所有文章。连同它的唯一 ID。以便用户可以查看自己需要删除的项目。
我的代码现在完全混乱了,甚至我自己都无法弄清楚。如果有人可以解释它,或者向我指出有关此主题的文章/教程,我将不胜感激。
这是我目前所拥有的,但正如所说的;真是一团糟:
string connectionString = Properties.Settings.Default.Database;
string selectString = "select artikelnummer, omschrijving from Artikels";
SqlCeDataAdapter sqlDataAdapter = new SqlCeDataAdapter();
DataSet dataSet = new DataSet();
try
{
using (SqlCeConnection connection = new SqlCeConnection(connectionString))
using (SqlCeCommand query = new SqlCeCommand(selectString, connection))
{
connection.Open();
string dataTableName = "Artikels";
sqlDataAdapter.Fill(dataSet, dataTableName);
DataTable dataTable = dataSet.Tables[dataTableName];
foreach (DataRow dataRow in dataTable.Rows)
{
listboxGeselecteerd.Items.Add(dataRow);
}
connection.Close();
}
}
I've been following tutorials to select rows from a table and display it in a checkedListbox. This works fine with only one column. However, I cannot seem to figure out how to do this while selecting multiple columns. Google isn't very helpful either.
I need to display all articles, from a stock. Together with it's unique ID. So that the user can check the items he needs to delete.
My code is completely messed up now, and can't even figure it out myself. Would appreciate if someone could explain it, or point me to an article/tutorial on this subject.
This is what I currently have, but as said; it's quite messed up:
string connectionString = Properties.Settings.Default.Database;
string selectString = "select artikelnummer, omschrijving from Artikels";
SqlCeDataAdapter sqlDataAdapter = new SqlCeDataAdapter();
DataSet dataSet = new DataSet();
try
{
using (SqlCeConnection connection = new SqlCeConnection(connectionString))
using (SqlCeCommand query = new SqlCeCommand(selectString, connection))
{
connection.Open();
string dataTableName = "Artikels";
sqlDataAdapter.Fill(dataSet, dataTableName);
DataTable dataTable = dataSet.Tables[dataTableName];
foreach (DataRow dataRow in dataTable.Rows)
{
listboxGeselecteerd.Items.Add(dataRow);
}
connection.Close();
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论