Passing Parameters in a Select Statement

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Brian Conway

    Passing Parameters in a Select Statement

    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 (ConfigurationS ettings.AppSett ings["ReportRequestC onnectionSt
    ring"]);

    OleDbDataAdapte r da = new OleDbDataAdapte r(sqlQuery, conn);

    // OleDbParameter myParm = da.SelectComman d.Parameters.Ad d(ppRequestID,
    OleDbType.Numer ic, 8, ppRequestID);

    conn.Open();

    DataSet ds = new DataSet();

    da.Fill(ds, "Report");

    lblFirstName.Te xt = (string)ds.Tabl es[0].Rows[0]["created_by "];


    conn.Close();

    }


  • Arran Pearce

    #2
    Re: Passing Parameters in a Select Statement

    How have you defined ppRequestID?

    Brian Conway wrote:
    [color=blue]
    > 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 (ConfigurationS ettings.AppSett ings["ReportRequestC onnectionSt
    > ring"]);
    >
    > OleDbDataAdapte r da = new OleDbDataAdapte r(sqlQuery, conn);
    >
    > // OleDbParameter myParm = da.SelectComman d.Parameters.Ad d(ppRequestID,
    > OleDbType.Numer ic, 8, ppRequestID);
    >
    > conn.Open();
    >
    > DataSet ds = new DataSet();
    >
    > da.Fill(ds, "Report");
    >
    > lblFirstName.Te xt = (string)ds.Tabl es[0].Rows[0]["created_by "];
    >
    >
    > conn.Close();
    >
    > }
    >
    >[/color]

    Comment

    • Jon Skeet [C# MVP]

      #3
      Re: Passing Parameters in a Select Statement

      Brian Conway <Brian.Conway@q west.com> wrote:[color=blue]
      > 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 (ConfigurationS ettings.AppSett ings["ReportRequestC onnectionSt
      > ring"]);
      >
      > OleDbDataAdapte r da = new OleDbDataAdapte r(sqlQuery, conn);
      >
      > // OleDbParameter myParm = da.SelectComman d.Parameters.Ad d(ppRequestID,
      > OleDbType.Numer ic, 8, ppRequestID);
      >
      > conn.Open();
      >
      > DataSet ds = new DataSet();
      >
      > da.Fill(ds, "Report");
      >
      > lblFirstName.Te xt = (string)ds.Tabl es[0].Rows[0]["created_by "];
      >
      >
      > conn.Close();
      >
      > }[/color]

      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.

      --
      Jon Skeet - <skeet@pobox.co m>
      Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

      If replying to the group, please do not mail me too

      Comment

      • Brian Conway

        #4
        Re: Passing Parameters in a Select Statement

        I figured it out I used

        da.SelectComman d.Parameters.Ad d(ppRequestID, OleDbType.Numer ic, 8).Value =
        ppRequestID;

        and this worked fine.


        "Brian Conway" <Brian.Conway@q west.com> wrote in message
        news:uLG9rW$bEH A.4092@TK2MSFTN GP11.phx.gbl...[color=blue]
        > 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
        >[/color]
        OleDbConnection (ConfigurationS ettings.AppSett ings["ReportRequestC onnectionSt[color=blue]
        > ring"]);
        >
        > OleDbDataAdapte r da = new OleDbDataAdapte r(sqlQuery, conn);
        >
        > // OleDbParameter myParm = da.SelectComman d.Parameters.Ad d(ppRequestID,
        > OleDbType.Numer ic, 8, ppRequestID);
        >
        > conn.Open();
        >
        > DataSet ds = new DataSet();
        >
        > da.Fill(ds, "Report");
        >
        > lblFirstName.Te xt = (string)ds.Tabl es[0].Rows[0]["created_by "];
        >
        >
        > conn.Close();
        >
        > }
        >
        >[/color]


        Comment

        Working...