I am doing a Quiz Generator / Viewer project, which requries the use of a database for the numerous questions the teacher has to put in, as well as the user names, passwords, etc. I used Microsoft Access (2000, I think) because I found it easier to use.

For the most part, the program works fine, except when it comes to a form that reads from a column inside the database.

This is the code which returns an *IndexOutofRangeException* (or something like that):

sConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=QMDbase.mdb";
                    OleDbConnection dbConn;
                    dbConn = new OleDbConnection(sConnection);
                    sql = "SELECT quesItem FROM quesAll WHERE userCourse = '" + cmboCourse.Text + "' AND quizWeek = '" + week1.ToString() + "';";
                    OleDbCommand dbCmd = new OleDbCommand();
                    dbCmd.CommandText = sql;
                    dbCmd.Connection = dbConn;
                    OleDbDataReader dbReader;
                    dbReader = dbCmd.ExecuteReader();

                    while (dbReader.Read())
                        question = dbReader["quesItem"].ToString();
                        qtype = dbReader["quesSort"].ToString();
                        if (qtype == "ID")
                            if (lstQuesID.Items.Contains(question))
                        else if (qtype == "MC")
                            if (lstQuesMC.Items.Contains(question))
                        else if (qtype == "TF")
                            if (lstQuesTF.Items.Contains(question))

Apparently, the program is unable to find the column quesSort (which exists). I tried going around this problem, byt changing the SQL line to the following:

sql = "SELECT quesItem FROM quesAll WHERE userCourse = '" + cmboCourse.Text + "' AND quizWeek = '" + week1.ToString() + "' AND quizSort = '" + qtypeID + "';";

But the program returns a *No value given for one or more parameters* (which exists). I'm convinced that the program cannot read from the column properly, even though I could read and write into it fine on other forms (in the same program).

On a side note, the entire program once gave me an error, something about being unable to find the proper forms for the program because I copied it from my files in school to my files at home. I *think* I fixed that by rebuilding it, and the problem never appeared again.

Building, cleaning, rebuilding the program doesn't work. I'm pretty much stuck here, and any help on the matter will be most appreciated. Thanks.

Attached with this is a picture of the database.

Column Description:
userCourse - Course of the Question
quesItem - The question
quesAnswer - The answer to the question
quesChoice1 - 4 - The other possible answers (in case of a Multiple Choice question)
quesSort - Type of question (ID = Identification, MC = Multiple Choice, TF = True or false)
studRate - Difficulty as rated by students
profRate = Difficulty as rated by professors
quizWeek - Week the quiz takes place
dateCreate - Date of creation

Edited by zack_falcon: n/a

Attachments Access.png 264.91 KB
6 Years
Discussion Span
Last Post by zack_falcon

Hi zack,

As I see from your code, you select only quesItem from DB and dbReader knows only about that column. In the select clause, write all the columns you want to manipulate.

sql = "SELECT quesItem, quesSort FROM quesAll WHERE userCourse = '" + cmboCourse.Text + "' AND quizWeek = '" + week1.ToString() + "';";
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.