Passing Parameters in a Select Statement

B

Brian Conway

I am trying to get a parameter passed from one page to another in a
QueryString to get inserted into the select statement on the page that is
getting called. If I hard code in a value everything works, but I can't
figure out how to get it to pass in as a parameter. Here is what I have.
The parameter section doesn't work though.

OleDbConnection conn = new
OleDbConnection(ConfigurationSettings.AppSettings["ReportRequestConnectionSt
ring"]);

OleDbDataAdapter da = new OleDbDataAdapter(sqlQuery, conn);

// OleDbParameter myParm = da.SelectCommand.Parameters.Add(ppRequestID,
OleDbType.Numeric, 8, ppRequestID);

conn.Open();

DataSet ds = new DataSet();

da.Fill(ds, "Report");

lblFirstName.Text = (string)ds.Tables[0].Rows[0]["created_by"];


conn.Close();

}
 
J

Jon Skeet [C# MVP]

Brian Conway said:
I am trying to get a parameter passed from one page to another in a
QueryString to get inserted into the select statement on the page that is
getting called. If I hard code in a value everything works, but I can't
figure out how to get it to pass in as a parameter. Here is what I have.
The parameter section doesn't work though.

OleDbConnection conn = new
OleDbConnection(ConfigurationSettings.AppSettings["ReportRequestConnectionSt
ring"]);

OleDbDataAdapter da = new OleDbDataAdapter(sqlQuery, conn);

// OleDbParameter myParm = da.SelectCommand.Parameters.Add(ppRequestID,
OleDbType.Numeric, 8, ppRequestID);

conn.Open();

DataSet ds = new DataSet();

da.Fill(ds, "Report");

lblFirstName.Text = (string)ds.Tables[0].Rows[0]["created_by"];


conn.Close();

}

What value are you trying to set for the parameter? If it's
ppRequestID, then you should be aware that the method you're calling is
using that as the *name* of the parameter, not the value. Use the Value
property of the parameter to set its value.
 
B

Brian Conway

I figured it out I used

da.SelectCommand.Parameters.Add(ppRequestID, OleDbType.Numeric, 8).Value =
ppRequestID;

and this worked fine.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top