Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/278.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2008/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 无法使用c查询数据_C#_Visual Studio 2008_Ms Access - Fatal编程技术网

C# 无法使用c查询数据

C# 无法使用c查询数据,c#,visual-studio-2008,ms-access,C#,Visual Studio 2008,Ms Access,我有三张桌子:课程、课文和书籍。我在执行以下代码时出错- 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

我有三张桌子:课程、课文和书籍。我在执行以下代码时出错-

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.Fillds,text行中遇到一个错误;
当我不使用自然连接并执行简单查询时,我得到的是正确的输出。代码出了什么问题?

我想可能是您的SQL查询的这一部分

(select count(book_isbn) from Book_Adoption
您选择的是计数而不是列,这可能会导致问题,因为它不知道列名。
请参阅以了解类似的情况。

请包括您收到的实际错误的详细信息。OLEDBEException未经处理。IErrorInfo.GetDescription因E_FAIL0x80004005而失败。如果dt是DataTable,您不能只使用da.Filldt?当我这样做时,我得到了这个错误-值不能为空。参数名称:DataTable导致问题的连接是什么?我不熟悉自然连接,但是否存在未设置主键的情况?如果您直接在Access上运行查询,它是否有效?下面是Nanhydrin给出的答案。您能在Access中运行此查询而不出错吗:从文本中选择课程id、图书isbn、图书标题自然加入图书采纳自然加入课程(存在)从图书采纳自然加入课程组按课程id>1的部门按图书标题排序