如何从 SQLCE 数据库中执行多列 SELECT 操作?
因为我的上一个问题没有返回任何有用的信息,所以我不得不问另一个问题。
情况:
我有一个本地SQLCE数据库。它包含 2 个表; “Artikels”和“Leggers”(不要介意荷兰名字,不会改变情况)。我要查询的表包含“Artikelnummer”、“Omschrijving”、“Legger”和“Voorraad”列。
我想要做的:
查询表“Artikels”中的“Artikelnummer”和“Omschrijving”,然后将其显示在 CheckedListbox 中,最好有两列单独的列(如果不能与多个列一起使用,则只有一列)。
我从此处的教程和答案中汇总的代码:
private void populateListbox()
{
string connectionString = Properties.Settings.Default.Database;
string selectString = "select artikelnummer, omschrijving from Artikels";
SqlCeDataAdapter sqlDataAdapter = new SqlCeDataAdapter();
DataSet dataSet = new DataSet();
using (SqlCeConnection connection = new SqlCeConnection(connectionString))
using (SqlCeCommand query = new SqlCeCommand(selectString, connection))
{
connection.Open();
string dataTableName = "Artikels";
sqlDataAdapter.SelectCommand = new SqlCeCommand(selectString);
DataTable dataTable = dataSet.Tables[dataTableName];
listboxGeselecteerd.DataSource = dataSet.Tables[dataTableName];
listboxGeselecteerd.ValueMember = "[Artikelnummer]";
listboxGeselecteerd.DisplayMember = "[Omschrijving]";
connection.Close();
}
}
我没有收到任何错误,但在调试时我发现 DataTable dataTable = dataSet.Tables[dataTableName];
上没有任何反应。
我已经用谷歌搜索过,但我没有读到任何提到选择多列的内容。
顺便说一下,我使用的是VS2010。
Because my last question didn't return anything useful, I will have to ask yet another question.
The situation:
I have a local SQLCE database. It contains 2 tables; "Artikels" and "Leggers" (Don't mind the Dutch names, doesn't change the situation). The table I'll be querying has the columns "Artikelnummer", "Omschrijving", "Legger", and "Voorraad".
What I want to do:
Query the table "Artikels" for "Artikelnummer" and "Omschrijving" and then display it in a CheckedListbox, preferably with two seperate columns (or just one if it doesn't work with multiple).
The code I have put together from tutorials and answers here:
private void populateListbox()
{
string connectionString = Properties.Settings.Default.Database;
string selectString = "select artikelnummer, omschrijving from Artikels";
SqlCeDataAdapter sqlDataAdapter = new SqlCeDataAdapter();
DataSet dataSet = new DataSet();
using (SqlCeConnection connection = new SqlCeConnection(connectionString))
using (SqlCeCommand query = new SqlCeCommand(selectString, connection))
{
connection.Open();
string dataTableName = "Artikels";
sqlDataAdapter.SelectCommand = new SqlCeCommand(selectString);
DataTable dataTable = dataSet.Tables[dataTableName];
listboxGeselecteerd.DataSource = dataSet.Tables[dataTableName];
listboxGeselecteerd.ValueMember = "[Artikelnummer]";
listboxGeselecteerd.DisplayMember = "[Omschrijving]";
connection.Close();
}
}
I don't get any errors, but while debugging I have seen that nothing is happening from DataTable dataTable = dataSet.Tables[dataTableName];
on.
I have googled it, but nothing I have read mentioned selecting multiple columns.
I am using VS2010, by the way.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您似乎忘记调用
Fill
方法:It looks like you've forgotten to call the
Fill
method: