473,414 Members | 1,598 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

dataAdapter.UpdateCommand-adding param value inline problem

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
Jun 2 '06 #1
1 4248
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:
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

Jun 2 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: G-Fit | last post by:
Hello group, I have several servers hosting SQL databases. On each of them, I have several databases. All those databases have the same structure (even those on different servers), only the data...
4
by: Job Lot | last post by:
am binding my DataGrid using a StoredProc which uses an OuterJoin query as follows: CREATE PROCEDURE spGetClientExpenses @Client_ID int AS SELECT...
2
by: Joe Fetters via .NET 247 | last post by:
Have googled and read the VS.NET documentation can't seem to getthe answer to the following. Environment: Framework 1.1 VB.NET WinForm Access database Using all automagic tools (DataAdapter...
1
by: Marina | last post by:
The commands that are generated by the SqlCommandBuilder are not quite right. I am calling GetUpdateCommand and GetDeleteCommand, modifying the results, and assigning them to the UpdateCommand and...
1
by: Julia Sats | last post by:
Hi, This is code from MSDN help (OracleDataAdapter.UpdateCommand Property) ' Create the UpdateCommand. cmd = New OracleCommand("UPDATE Dept SET DeptNo = pDeptNo, DName = pDName " & _ "WHERE...
9
by: cherishman | last post by:
When I use self-defined database, sometimes the dataadapter can't auto create insertcommand, updatecommand and deletecommand, it just only create selectcommand? But when I use these database such...
4
by: astro | last post by:
I would like to build some generic code that is able to figure out the correct dataAdapter to apply changes to given a form with several dataAdapters. Any suggestions on the following? Thank...
6
by: Rich | last post by:
Dim da As New SqlDataAdapter("Select * from tbl1", conn) dim tblx As New DataTable da.Fill(tblx) '--works OK up to this point da.UpdateCommand = New SqlCommand da.UpdateCommand.Connection =...
3
by: Rich | last post by:
What is the diffeence bewtween a dataAdapter.InsertCommand and dataAdapter.SelectCommand (and dataAdapter.UpdateCommand for that matter)? Dim da As SqlDataAdapter conn.Open da.SelectCommand =...
0
by: snow | last post by:
Hello, I have a VS 2003.NET application that connects to a Access database. I want to make its code work in VS 2005. Here is the code for VS 2003 .NET: da1.UpdateCommand.CommandText = "update...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.