sqlDataSource parameter

Discussion in 'ASP .Net' started by Keith G Hicks, Apr 3, 2008.

  1. asp.net 2.0

    When I use the wizard in VWD 2005 to set up a sqlDataSource it creates code
    like this for the UpdateCommand:

    UpdateCommand="UPDATE [Customers] SET [CustomerName] = @CustomerName, .....
    WHERE ....

    When I bind text boxes to the values in the SelectCommand, how does the
    UpdateCommand know that the @CustomerName parameter goes with the correct
    text box. Is it that the Bind("CustomerName") has the same field name as the
    name of the "@" parameter? I don't see anythign else in the code that's
    generated that would do that.

    Ok, so having asked that here's my main question. I need to pass another
    value into the update command that's NOT bound to a text box. For example:

    UpdateCommand="UPDATE [Customers] SET [CustomerName] = @CustomerName,
    [UpdatedBy] = ???????? ..... WHERE ....

    I need to post the currently logged in user (My.User.Name) to the
    "UpdatedBy" field in the database. How do I do this?

    Lastly, when the wizard generates the UpdateCommand and DeleteCommand, why
    does it put ALL the fields in the WHERE clause? That makes no sense to me. I
    would normally only put the PK in the WHERE clause in an Update or Delete
    statement.

    Thanks (still learning),

    Keith
    Keith G Hicks, Apr 3, 2008
    #1
    1. Advertising

  2. Keith G Hicks

    Patrice Guest

    Inline...

    > When I bind text boxes to the values in the SelectCommand, how does the
    > UpdateCommand know that the @CustomerName parameter goes with the correct
    > text box. Is it that the Bind("CustomerName") has the same field name as
    > the
    > name of the "@" parameter? I don't see anythign else in the code that's
    > generated that would do that.


    http://msdn2.microsoft.com/en-us/library/xt50s8kz(VS.80).aspx

    Don't you see this section in your ASPX markup ? Don't you have defined this
    ?

    >
    > Ok, so having asked that here's my main question. I need to pass another
    > value into the update command that's NOT bound to a text box. For example:
    >
    > UpdateCommand="UPDATE [Customers] SET [CustomerName] = @CustomerName,
    > [UpdatedBy] = ???????? ..... WHERE ....
    > I need to post the currently logged in user (My.User.Name) to the
    > "UpdatedBy" field in the database. How do I do this?


    Choose something from the article above and use this as a source ?
    >
    > Lastly, when the wizard generates the UpdateCommand and DeleteCommand, why
    > does it put ALL the fields in the WHERE clause? That makes no sense to me.
    > I
    > would normally only put the PK in the WHERE clause in an Update or Delete
    > statement.


    This is to handle optimistic concurrency. It uses the original values (in
    addtion to the pk) so if someone changed this row, the clause where won't
    match and so it means that someone changed this row while you were editing
    it... When usign SQL Server a timestamp (rowversion) column (that is updated
    automatically each time the row is updated) can be more convenient...

    >
    > Thanks (still learning),
    >
    > Keith
    >
    >
    Patrice, Apr 3, 2008
    #2
    1. Advertising

  3. Thanks Patrice. That helped a lot. One thing I'm still not clear on. If the
    Update, Select, ... Commands have more than one parameter, is it the ORDER
    of them that counts? In one of the samples on the link you sent me below
    they have multiple parameters. In the InsertCommand they are

    @LastName, @FirstName, @Address, @City, @Region, @PostalCode

    In the parameters definition they have:

    <InsertParameters>
    <asp:parameter Name="LastName" Type="String" />
    <asp:parameter Name="FirstName" Type="String" />
    <asp:parameter Name="Address" Type="String" />
    <asp:parameter Name="City" Type="String" />
    <asp:parameter Name="Region" Type="String" />
    <asp:parameter Name="PostalCode" Type="String" />
    <asp:parameter Name="EmpID" Direction="Output" Type="Int32"
    DefaultValue="0" />
    </InsertParameters>

    They are in order but they also have the same names. I'm guessing that it's
    the order that's important and not the names but I'm not entirely sure.

    Thanks,

    Keith


    "Patrice" <http://www.chez.com/scribe/> wrote in message
    news:#U8i#$...
    > Inline...
    >
    > > When I bind text boxes to the values in the SelectCommand, how does the
    > > UpdateCommand know that the @CustomerName parameter goes with the

    correct
    > > text box. Is it that the Bind("CustomerName") has the same field name as
    > > the
    > > name of the "@" parameter? I don't see anythign else in the code that's
    > > generated that would do that.

    >
    > http://msdn2.microsoft.com/en-us/library/xt50s8kz(VS.80).aspx
    >
    > Don't you see this section in your ASPX markup ? Don't you have defined

    this
    > ?
    >
    > >
    > > Ok, so having asked that here's my main question. I need to pass another
    > > value into the update command that's NOT bound to a text box. For

    example:
    > >
    > > UpdateCommand="UPDATE [Customers] SET [CustomerName] = @CustomerName,
    > > [UpdatedBy] = ???????? ..... WHERE ....
    > > I need to post the currently logged in user (My.User.Name) to the
    > > "UpdatedBy" field in the database. How do I do this?

    >
    > Choose something from the article above and use this as a source ?
    > >
    > > Lastly, when the wizard generates the UpdateCommand and DeleteCommand,

    why
    > > does it put ALL the fields in the WHERE clause? That makes no sense to

    me.
    > > I
    > > would normally only put the PK in the WHERE clause in an Update or

    Delete
    > > statement.

    >
    > This is to handle optimistic concurrency. It uses the original values (in
    > addtion to the pk) so if someone changed this row, the clause where won't
    > match and so it means that someone changed this row while you were editing
    > it... When usign SQL Server a timestamp (rowversion) column (that is

    updated
    > automatically each time the row is updated) can be more convenient...
    >
    > >
    > > Thanks (still learning),
    > >
    > > Keith
    > >
    > >

    >
    >
    Keith G Hicks, Apr 3, 2008
    #3
    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. Andrew
    Replies:
    3
    Views:
    2,882
    Andrew
    Apr 1, 2004
  2. Karl
    Replies:
    2
    Views:
    25,449
  3. Stu
    Replies:
    0
    Views:
    390
  4. Wayne Wengert

    Problem Using GUID as SQLDataSource Parameter

    Wayne Wengert, Feb 5, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    5,756
    Wayne Wengert
    Feb 6, 2006
  5. Jim Andersen
    Replies:
    3
    Views:
    6,971
    Alex D.
    Mar 3, 2006
Loading...

Share This Page