Passing Parameters in a Select Statement

  • Thread starter Thread starter Brian Conway
  • Start date Start date
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();

}
 
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.
 
I figured it out I used

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

and this worked fine.
 
Back
Top