PDA

View Full Version : OleDbDataReader


srhone
08-02-2004, 01:23 AM
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.CloseConnecti on);

bruce
08-02-2004, 07:58 AM
Can you post the complete code? as well as the error messages?

[b]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.CloseConnecti on);


</blockquote id="quote"></font id="quote">

bruce
08-03-2004, 01:09 AM
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.

[b]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>");
}


}




[b]quote:Originally posted by bruce

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

[b]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.CloseConnecti on);


</blockquote id="quote"></font id="quote">
</blockquote id="quote"></font id="quote">
</blockquote id="quote"></font id="quote">

srhone
08-03-2004, 06:33 AM
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>");
}


}




[b]quote:Originally posted by bruce

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

[b]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.CloseConnecti on);


</blockquote id="quote"></font id="quote">
</blockquote id="quote"></font id="quote">