Help with reading C# Access Database

Discussion in 'C#' started by zack_falcon, Aug 28, 2010.

  1. zack_falcon

    zack_falcon New Member

    Aug 28, 2010
    Likes Received:
    Trophy Points:
    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

    Attached Thumbnails [​IMG]

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice