dataAdapter.UpdateCommand-adding param value inline problem

G

Guest

Hello,

I can update a dataset from my client app using a dataAdapter.Updatecommand
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.UpdateCommand = New SqlCommand
daU.UpdateCommand.Connection = conn
daU.UpdateCommand.Parameters.Add(New SqlParameter("@p0", SqlDbType.Int))
daU.UpdateCommand.Parameters.Add(New SqlParameter("@p1", SqlDbType.VarChar,
50))

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

daU.UpdateCommand.Parameters("@p0").Value = txtID.Text
daU.UpdateCommand.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.UpdateCommand = New SqlCommand
daU.UpdateCommand.Connection = conn
daU.UpdateCommand.Parameters.Add(New SqlParameter("@p0", SqlDbType.Int, 4,
"ID" ))
daU.UpdateCommand.Parameters.Add(New SqlParameter("@p1", SqlDbType.VarChar,
50, "tName"))

daU.UpdateCommand.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
 
G

Guest

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top