0

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?

6
  • Please include details of the actual error you're getting. Commented Feb 21, 2012 at 10:44
  • OleDbException was unhandled IErrorInfo.GetDescription failed with E_FAIL(0x80004005). Commented Feb 21, 2012 at 10:45
  • if dt is DataTable couldnt you just use da.Fill(dt); ? Commented Feb 21, 2012 at 10:46
  • when i do that i am getting this error- Value cannot be null. Parameter name: dataTable Commented Feb 21, 2012 at 10:47
  • What is about the joins that causes problems? I'm not familiar with natural joins but is there a case of primary keys not being set? If you run the query on Access directly does it work? Commented Feb 21, 2012 at 10:49

1 Answer 1

1

I think it might be this bit of your SQL query

(select count(book_isbn) from Book_Adoption

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Following on from the answer Nanhydrin makes. Can you run this query in Access with no errors: "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"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.