dataAdapter.UpdateCommand-adding param value inline problem

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

    #1

    dataAdapter.UpdateCommand-adding param value inline problem

    Hello,

    I can update a dataset from my client app using a dataAdapter.Upd atecommand
    when I add parameter values outside of the param declaration. But If I add
    the param values inline with the param delcaration, then I have to invoke the
    update operation twice - by leaving the updated row - returning to the row
    and re-invoking the update procedure. Is there something else I need to do
    to add param values inline with the param declaration?

    param values added outside of param declaration - works OK:

    Private Sub Button4_Click(. ..) Handles Button4.Click
    Dim daU As New SqlDataAdapter
    daU.UpdateComma nd = New SqlCommand
    daU.UpdateComma nd.Connection = conn
    daU.UpdateComma nd.Parameters.A dd(New SqlParameter("@ p0", SqlDbType.Int))
    daU.UpdateComma nd.Parameters.A dd(New SqlParameter("@ p1", SqlDbType.VarCh ar,
    50))

    daU.UpdateComma nd.CommandText = "Update tbl1 set tName = @p1 Where tID = @p0"

    daU.UpdateComma nd.Parameters(" @p0").Value = txtID.Text
    daU.UpdateComma nd.Parameters(" @p1").Value = txtTname.Text

    daU.Update(ds, "tbl1")
    End Sub
    -----------------------------------------------------------------------------

    param values added inline with param declaration - have to invoke twice to
    get update - must leave row first and then return:

    Private Sub Button4_Click(. ..) Handles Button4.Click
    Dim daU As New SqlDataAdapter
    daU.UpdateComma nd = New SqlCommand
    daU.UpdateComma nd.Connection = conn
    daU.UpdateComma nd.Parameters.A dd(New SqlParameter("@ p0", SqlDbType.Int, 4,
    "ID" ))
    daU.UpdateComma nd.Parameters.A dd(New SqlParameter("@ p1", SqlDbType.VarCh ar,
    50, "tName"))

    daU.UpdateComma nd.CommandText = "Update tbl1 set tName = @p1 Where tID = @p0"

    daU.Update(ds, "tbl1")
    End Sub
    --------------------------------------------------------------------------

    Is there something else I need to do to Way2 to make it work when adding
    param values inline with the param declaration?

    Thanks,
    Rich
  • Rich

    #2
    RE: dataAdapter.Upd ateCommand-adding param value inline problem

    I think I see what is going on here. The row is updating to the original row
    because the value is not really being specified the way I have it set up in
    the inline param thing. I did try filling in all the arguments for the
    sqlparameter declare where the value is added at the very end - that is too
    much argument stuff. I guess I am stuck with adding the param values after
    the declaration. My thing is that the actual procedure has several fields -
    so I have several param declares and then have to add values to all those
    params.


    "Rich" wrote:
    [color=blue]
    > Hello,
    >
    > I can update a dataset from my client app using a dataAdapter.Upd atecommand
    > when I add parameter values outside of the param declaration. But If I add
    > the param values inline with the param delcaration, then I have to invoke the
    > update operation twice - by leaving the updated row - returning to the row
    > and re-invoking the update procedure. Is there something else I need to do
    > to add param values inline with the param declaration?
    >
    > param values added outside of param declaration - works OK:
    >
    > Private Sub Button4_Click(. ..) Handles Button4.Click
    > Dim daU As New SqlDataAdapter
    > daU.UpdateComma nd = New SqlCommand
    > daU.UpdateComma nd.Connection = conn
    > daU.UpdateComma nd.Parameters.A dd(New SqlParameter("@ p0", SqlDbType.Int))
    > daU.UpdateComma nd.Parameters.A dd(New SqlParameter("@ p1", SqlDbType.VarCh ar,
    > 50))
    >
    > daU.UpdateComma nd.CommandText = "Update tbl1 set tName = @p1 Where tID = @p0"
    >
    > daU.UpdateComma nd.Parameters(" @p0").Value = txtID.Text
    > daU.UpdateComma nd.Parameters(" @p1").Value = txtTname.Text
    >
    > daU.Update(ds, "tbl1")
    > End Sub
    > -----------------------------------------------------------------------------
    >
    > param values added inline with param declaration - have to invoke twice to
    > get update - must leave row first and then return:
    >
    > Private Sub Button4_Click(. ..) Handles Button4.Click
    > Dim daU As New SqlDataAdapter
    > daU.UpdateComma nd = New SqlCommand
    > daU.UpdateComma nd.Connection = conn
    > daU.UpdateComma nd.Parameters.A dd(New SqlParameter("@ p0", SqlDbType.Int, 4,
    > "ID" ))
    > daU.UpdateComma nd.Parameters.A dd(New SqlParameter("@ p1", SqlDbType.VarCh ar,
    > 50, "tName"))
    >
    > daU.UpdateComma nd.CommandText = "Update tbl1 set tName = @p1 Where tID = @p0"
    >
    > daU.Update(ds, "tbl1")
    > End Sub
    > --------------------------------------------------------------------------
    >
    > Is there something else I need to do to Way2 to make it work when adding
    > param values inline with the param declaration?
    >
    > Thanks,
    > Rich[/color]

    Comment

    Working...