无法使用c#查询数据
我有三个表 course、text 和 book_adoption。当我执行以下代码时,我收到错误 -
connect();
string qstr = "select course_id, book_isbn, book_title from texts natural join Book_Adoption natural join course where exists(select count(book_isbn) from Book_Adoption natural join course group by dept having count(course_id)>1) order by book_title";
da = new OleDbDataAdapter(qstr, con);
ds = new DataSet();
da.Fill(ds, "course");
//da.Fill(ds, "Texts");
//da.Fill(ds, "Book_Adoption");
dt = ds.Tables[0];
for (int i = 0; i < dt.Rows.Count; i++)
{
listBox1.Items.Add(dt.Rows[i]["course_id"].ToString());
listBox1.Items.Add(dt.Rows[i]["book_isbn"].ToString());
listBox1.Items.Add(dt.Rows[i]["book_title"].ToString());
}
我在 da.Fill(ds, "texts"); 行中收到错误 当我不使用自然连接并执行简单查询时,我会得到正确的输出。代码有什么问题吗?
I have three tables course, texts and book_adoption. I am getting an error when i am executing the following code-
connect();
string qstr = "select course_id, book_isbn, book_title from texts natural join Book_Adoption natural join course where exists(select count(book_isbn) from Book_Adoption natural join course group by dept having count(course_id)>1) order by book_title";
da = new OleDbDataAdapter(qstr, con);
ds = new DataSet();
da.Fill(ds, "course");
//da.Fill(ds, "Texts");
//da.Fill(ds, "Book_Adoption");
dt = ds.Tables[0];
for (int i = 0; i < dt.Rows.Count; i++)
{
listBox1.Items.Add(dt.Rows[i]["course_id"].ToString());
listBox1.Items.Add(dt.Rows[i]["book_isbn"].ToString());
listBox1.Items.Add(dt.Rows[i]["book_title"].ToString());
}
I am getting an error in the line da.Fill(ds, "texts");
When I am not using a natural join and doing a simple query, I am getting the correct output. WHat is wrong with the code?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为这可能是您的 SQL 查询的这一点
您选择的是计数而不是列,这可能会导致问题,因为它不知道列名称。
请参阅此处了解类似信息设想。
I think it might be this bit of your SQL query
You're selecting a count not a column and this may be causing a problem because it doesn't know the column name.
See here for a similar scenario.