OleDbDataReader

Discussion in 'Databases' started by srhone, Aug 2, 2004.

Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.
  1. Getting an error when trying to open a datareader. The code works upto this point, I checked the db connection status but the code below gets the error "No value given for one or more required parameters". I've checked all the documentation on it and do not see what is wrong.

    OleDbDataReader oleReader = oleCmd.ExecuteReader(CommandBehavior.CloseConnection);
     
  2. Bruce

    Bruce DiscountASP.NET Staff

    Can you post the complete code? as well as the error messages?

    quote:Originally posted by srhone

    Getting an error when trying to open a datareader. The code works upto this point, I checked the db connection status but the code below gets the error "No value given for one or more required parameters". I've checked all the documentation on it and do not see what is wrong.

    OleDbDataReader oleReader = oleCmd.ExecuteReader(CommandBehavior.CloseConnection);


    </blockquote id="quote"></font id="quote">
     
  3. Bruce

    Bruce DiscountASP.NET Staff

    The code looks fine to me.

    i actually test it in my test account. i think the problem may have something to do with the query.

    quote:Originally posted by srhone

    This is the code-behind portion of it and is executed from a link on another page. Notice I also use nCnt to locate the last line of executed code and output it in the error message.

    private void Page_Load(object sender, System.EventArgs e)
    {
    dbConn();
    }
    private void dbConn()
    {
    int nCnt = 0;
    try
    {

    //Works
    string strConn = "Provider=Microsoft.Jet.OleDB.4.0;Data Source=" + Server.MapPath("/_database/chemistry.mdb") + ";User ID=Admin";

    //OLE DB connection
    OleDbConnection conn = new OleDbConnection(strConn);
    conn.Open();

    Response.Write("Connection state: " + conn.State + "
    ");

    //OLE command
    string strSQL = "Select * from tbl_Pictures where pic_Category = '" + "Flight" + "'";

    nCnt = 1;
    Response.Write(strSQL + "
    ");
    OleDbCommand oleCmd = new OleDbCommand(strSQL,conn);

    nCnt = 2;

    //OLE Data Reader
    OleDbDataReader oleReader = oleCmd.ExecuteReader();

    nCnt = 3;
    while (oleReader.Read())
    {
    Response.Write("<p>" + oleReader.GetString(4) + "</p>
    ");
    }

    oleReader.Close();
    conn.Close();


    Response.Write("<p>" + nCnt + "</p>");
    }
    catch(Exception ex)
    {
    Response.Write("<p>ERROR : " + ex.Message + nCnt + "</p>");
    }


    }




    quote:Originally posted by bruce

    Can you post the complete code? as well as the error messages?

    quote:Originally posted by srhone

    Getting an error when trying to open a datareader. The code works upto this point, I checked the db connection status but the code below gets the error "No value given for one or more required parameters". I've checked all the documentation on it and do not see what is wrong.

    OleDbDataReader oleReader = oleCmd.ExecuteReader(CommandBehavior.CloseConnection);


    </blockquote id="quote"></font id="quote">
    </blockquote id="quote"></font id="quote">
    </blockquote id="quote"></font id="quote">
     
  4. This is the code-behind portion of it and is executed from a link on another page. Notice I also use nCnt to locate the last line of executed code and output it in the error message.

    private void Page_Load(object sender, System.EventArgs e)
    {
    dbConn();
    }
    private void dbConn()
    {
    int nCnt = 0;
    try
    {

    //Works
    string strConn = "Provider=Microsoft.Jet.OleDB.4.0;Data Source=" + Server.MapPath("/_database/chemistry.mdb") + ";User ID=Admin";

    //OLE DB connection
    OleDbConnection conn = new OleDbConnection(strConn);
    conn.Open();

    Response.Write("Connection state: " + conn.State + "
    ");

    //OLE command
    string strSQL = "Select * from tbl_Pictures where pic_Category = '" + "Flight" + "'";

    nCnt = 1;
    Response.Write(strSQL + "
    ");
    OleDbCommand oleCmd = new OleDbCommand(strSQL,conn);

    nCnt = 2;

    //OLE Data Reader
    OleDbDataReader oleReader = oleCmd.ExecuteReader();

    nCnt = 3;
    while (oleReader.Read())
    {
    Response.Write("<p>" + oleReader.GetString(4) + "</p>
    ");
    }

    oleReader.Close();
    conn.Close();


    Response.Write("<p>" + nCnt + "</p>");
    }
    catch(Exception ex)
    {
    Response.Write("<p>ERROR : " + ex.Message + nCnt + "</p>");
    }


    }




    quote:Originally posted by bruce

    Can you post the complete code? as well as the error messages?

    quote:Originally posted by srhone

    Getting an error when trying to open a datareader. The code works upto this point, I checked the db connection status but the code below gets the error "No value given for one or more required parameters". I've checked all the documentation on it and do not see what is wrong.

    OleDbDataReader oleReader = oleCmd.ExecuteReader(CommandBehavior.CloseConnection);


    </blockquote id="quote"></font id="quote">
    </blockquote id="quote"></font id="quote">
     
Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.

Share This Page