parameter passing asp.net vb

Discussion in 'ASP .Net' started by Ben Barnes, Jan 27, 2005.

  1. Ben Barnes

    Ben Barnes Guest

    hi,

    I'm a relative newbie to .net but have been an asp developer for a few
    years. I'm starting the slow and somehwat painful process of learning
    how to do everything I used to do in asp in .net.

    i'm using visual studio and am simply trying to do the following:

    Pass a value into a stored procedure or a sql query which has been is
    passed via a querystring.

    I've achieved this by setting the value of the parameter in the
    desinger generated code but I would like to be able to handle this in
    the page_load. I'd like to check for the existence of a paramater and
    pass this value to the query.

    I'm sure it's really easy, it certainly is in classic asp but i'm
    really struggling with this one.

    Anyone help?
    Ben Barnes, Jan 27, 2005
    #1
    1. Advertising

  2. Ben Barnes

    Curt_C [MVP] Guest

    page_load.....

    if(Request.QueryString("val") != null)
    {
    string myVal = Request.QueryStirng("val");
    ...your other stuff....
    }

    --
    Curt Christianson
    Site & Scripts: http://www.Darkfalz.com
    Blog: http://blog.Darkfalz.com


    "Ben Barnes" <> wrote in message
    news:...
    > hi,
    >
    > I'm a relative newbie to .net but have been an asp developer for a few
    > years. I'm starting the slow and somehwat painful process of learning
    > how to do everything I used to do in asp in .net.
    >
    > i'm using visual studio and am simply trying to do the following:
    >
    > Pass a value into a stored procedure or a sql query which has been is
    > passed via a querystring.
    >
    > I've achieved this by setting the value of the parameter in the
    > desinger generated code but I would like to be able to handle this in
    > the page_load. I'd like to check for the existence of a paramater and
    > pass this value to the query.
    >
    > I'm sure it's really easy, it certainly is in classic asp but i'm
    > really struggling with this one.
    >
    > Anyone help?
    Curt_C [MVP], Jan 27, 2005
    #2
    1. Advertising

  3. Ben Barnes

    Guest

    Hi Curt,

    Thanks. the above I can handle but it is passing the value back into
    the query to be the parameter that I'm struggling with.

    So, it's a case of putting myVal back as the value of
    Me.SqlCommand1.Parameters.Add
    , Jan 27, 2005
    #3
  4. Ben Barnes

    Karl Seguin Guest

    Ben,
    It isn't too complicated, but it can certainly be confusing at first.
    Personally I'm not the biggest fan of design time stuff, I realize it's much
    quicker and simpler, but if you're like me, you like having a fine grain
    control. Additionally, you learn a lot more by doing it yourself.

    Having said that, I'm not 100% sure what step you are having a hard time
    with. Is it simply getting a value from the querystring? or assigning it as
    a parameter? Without knowing what you have, I'll show you a basic way of
    doing the entire thing:

    (code not compiled, typing it off the top of my head)

    Sub Page_Load
    dim id as integer = 0
    if Request.QueryString("userId") is nothing then
    id = -1 'some default value
    else
    id = Convert.ToInt32(Request.QueryString("userId")) 'could throw an
    exception if it isn't a valid it, so you might wanna try/catch this
    end if

    dim connection as new SqlConnection(CONNECTION_STRING)
    dim command as new SqlCommand(connection, "STORED_PROCEDURE_NAME")
    command.commandType = commandType.StoredProcedure
    command.Parameters.Add("@UserId", SqlDbType.Int).Value = id 'here's where
    you assign the variable to the sproc

    dim ds as new DataSet
    dim da as new SqlDataAdapter(command)
    try
    connection.Open()
    da.Fill(ds)
    finally
    connection.dispose()
    command.dispose()
    da.dispose()
    end try


    you now have a DataSet (ds) with the data..

    The above code should be moved into a utility function, which returns a
    dataset, so that you can reuse it, but other than that, all should be good.

    lemme know if anything specific irkes you.

    Karl


    --
    MY ASP.Net tutorials
    http://www.openmymind.net/


    "Ben Barnes" <> wrote in message
    news:...
    > hi,
    >
    > I'm a relative newbie to .net but have been an asp developer for a few
    > years. I'm starting the slow and somehwat painful process of learning
    > how to do everything I used to do in asp in .net.
    >
    > i'm using visual studio and am simply trying to do the following:
    >
    > Pass a value into a stored procedure or a sql query which has been is
    > passed via a querystring.
    >
    > I've achieved this by setting the value of the parameter in the
    > desinger generated code but I would like to be able to handle this in
    > the page_load. I'd like to check for the existence of a paramater and
    > pass this value to the query.
    >
    > I'm sure it's really easy, it certainly is in classic asp but i'm
    > really struggling with this one.
    >
    > Anyone help?
    Karl Seguin, Jan 27, 2005
    #4
  5. Ben Barnes

    Guest

    Hi Karl,

    Spot on, that looks like it will do the trick! thanks

    The thing is I'm doing this through Visual Studio and am draggin the
    tables onto the designer surface and hooking things up that way.
    Getting data out is fine and foring a parameter is also ok but getting
    the value of the parameter to be passedin at deisgn time is a touch
    more tricky.

    Thanks your help, I'll give it a go, but it looks like it will do the
    job perfectly. Thanks for taking the time to reply..
    , Jan 27, 2005
    #5
  6. Ben Barnes

    Curt_C [MVP] Guest

    ..Add("@paramName",myVal);

    --
    Curt Christianson
    Site & Scripts: http://www.Darkfalz.com
    Blog: http://blog.Darkfalz.com


    <> wrote in message
    news:...
    > Hi Curt,
    >
    > Thanks. the above I can handle but it is passing the value back into
    > the query to be the parameter that I'm struggling with.
    >
    > So, it's a case of putting myVal back as the value of
    > Me.SqlCommand1.Parameters.Add
    >
    Curt_C [MVP], Jan 27, 2005
    #6
  7. Ben Barnes

    Curt_C [MVP] Guest

    oops... typo... see what Karl wrote :}

    --
    Curt Christianson
    Site & Scripts: http://www.Darkfalz.com
    Blog: http://blog.Darkfalz.com


    <> wrote in message
    news:...
    > Hi Curt,
    >
    > Thanks. the above I can handle but it is passing the value back into
    > the query to be the parameter that I'm struggling with.
    >
    > So, it's a case of putting myVal back as the value of
    > Me.SqlCommand1.Parameters.Add
    >
    Curt_C [MVP], Jan 27, 2005
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. IMRAN
    Replies:
    1
    Views:
    461
    =?Utf-8?B?RWx0b24gVw==?=
    Jan 8, 2006
  2. Replies:
    4
    Views:
    507
    Matteo
    Mar 29, 2007
  3. Stuart Redmann
    Replies:
    5
    Views:
    468
    Stuart Redmann
    Dec 14, 2007
  4. Mister B
    Replies:
    8
    Views:
    530
    Nick Keighley
    Aug 26, 2010
  5. nungon
    Replies:
    9
    Views:
    144
Loading...

Share This Page