473,770 Members | 2,113 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

difference between dataAdapter.Ins ertCommand/dataAdapter.Sel ectCom

What is the diffeence bewtween a dataAdapter.Ins ertCommand and
dataAdapter.Sel ectCommand (and dataAdapter.Upd ateCommand for that matter)?

Dim da As SqlDataAdapter
conn.Open
da.SelectComman d = New SqlCommand
da.SelectComman d.Connectoin = conn
da.SelectComman d.CommandType = Command.Text
da.SelectComman d.CommandText = "insert Into tbl1 Select * from tbl2"
da.SelectComman d.ExecuteNonQue ry

Or

Dim da As SqlDataAdapter
conn.Open
da.InsertComman d = New SqlCommand
da.InsertComman d.Connectoin = conn
da.InsertComman d.CommandType = Command.Text
da.InsertComman d.CommandText = "insert Into tbl1 Select * from tbl2"
da.InsertComman d.ExecuteNonQue ry

Is there any differece between these 2 dataAdapters? It looks to me like
they both perform the same operation.

Thanks,
Rich
Nov 9 '06 #1
3 12514
I believe the answer to my question is that you can use the
dataAdapter.Upd ate method with dataAdapter.Ins ertCommand and
dataAdapter.Upd ate command, but you can only use dataAdapter.Fil l with the
dataAdapter.Sel ectCommand.

Any additional comments appreciated.

"Rich" wrote:
What is the diffeence bewtween a dataAdapter.Ins ertCommand and
dataAdapter.Sel ectCommand (and dataAdapter.Upd ateCommand for that matter)?

Dim da As SqlDataAdapter
conn.Open
da.SelectComman d = New SqlCommand
da.SelectComman d.Connectoin = conn
da.SelectComman d.CommandType = Command.Text
da.SelectComman d.CommandText = "insert Into tbl1 Select * from tbl2"
da.SelectComman d.ExecuteNonQue ry

Or

Dim da As SqlDataAdapter
conn.Open
da.InsertComman d = New SqlCommand
da.InsertComman d.Connectoin = conn
da.InsertComman d.CommandType = Command.Text
da.InsertComman d.CommandText = "insert Into tbl1 Select * from tbl2"
da.InsertComman d.ExecuteNonQue ry

Is there any differece between these 2 dataAdapters? It looks to me like
they both perform the same operation.

Thanks,
Rich
Nov 9 '06 #2
Hi,

"Rich" <Ri**@discussio ns.microsoft.co mwrote in message
news:80******** *************** ***********@mic rosoft.com...
>I believe the answer to my question is that you can use the
dataAdapter.Upd ate method with dataAdapter.Ins ertCommand and
dataAdapter.Upd ate command, but you can only use dataAdapter.Fil l with the
dataAdapter.Sel ectCommand.
DataAdapter.Upd ate(DataTable) will use UpdateCommand for each row that is
modified, InsertCommand for each new row and DeleteCommand for each deleted
row.

DataAdapter.Fil l(DataTable) will use the SelectCommand.

Notice that these Update, Insert, Delete Command's are not supposed to be
used like you do. Their SQL queries should include parameters which are
linked to the field (column) names in the DataTable and you should not call
ExecuteNonQuery on them.

If you want to execute a query like yours, then use a SqlCommand instead,
eg. :

Dim cmd As New SqlCommand()
cmd.Connection = conn
cmd.CommandType = Command.Text
cmd.CommandText = "insert Into tbl1 Select * from tbl2"
cmd.ExecuteNonQ uery()
HTH,
Greetings

>
Any additional comments appreciated.

"Rich" wrote:
>What is the diffeence bewtween a dataAdapter.Ins ertCommand and
dataAdapter.Se lectCommand (and dataAdapter.Upd ateCommand for that
matter)?

Dim da As SqlDataAdapter
conn.Open
da.SelectComma nd = New SqlCommand
da.SelectComma nd.Connectoin = conn
da.SelectComma nd.CommandType = Command.Text
da.SelectComma nd.CommandText = "insert Into tbl1 Select * from tbl2"
da.SelectComma nd.ExecuteNonQu ery

Or

Dim da As SqlDataAdapter
conn.Open
da.InsertComma nd = New SqlCommand
da.InsertComma nd.Connectoin = conn
da.InsertComma nd.CommandType = Command.Text
da.InsertComma nd.CommandText = "insert Into tbl1 Select * from tbl2"
da.InsertComma nd.ExecuteNonQu ery

Is there any differece between these 2 dataAdapters? It looks to me like
they both perform the same operation.

Thanks,
Rich

Nov 10 '06 #3
Rich wrote:
What is the diffeence bewtween a dataAdapter.Ins ertCommand and
dataAdapter.Sel ectCommand (and dataAdapter.Upd ateCommand for that matter)?

Dim da As SqlDataAdapter
conn.Open
da.SelectComman d = New SqlCommand
da.SelectComman d.Connectoin = conn
da.SelectComman d.CommandType = Command.Text
da.SelectComman d.CommandText = "insert Into tbl1 Select * from tbl2"
da.SelectComman d.ExecuteNonQue ry

Or

Dim da As SqlDataAdapter
conn.Open
da.InsertComman d = New SqlCommand
da.InsertComman d.Connectoin = conn
da.InsertComman d.CommandType = Command.Text
da.InsertComman d.CommandText = "insert Into tbl1 Select * from tbl2"
da.InsertComman d.ExecuteNonQue ry

Is there any differece between these 2 dataAdapters? It looks to me like
they both perform the same operation.

Thanks,
Rich
The DataAdapter is meant to make a DataGrid work like it was a real
table. That is, updating the grid should issue an UPDATE statement to
the real underlying table. And so on. By allowing these different
commands, there is a methodical way of keeping up this charade.

Ultimately, however, they are just Commands, and can be used for
whatever you'd like. But, it would be confusing to another programmer
reviewing your work.

B.

Nov 10 '06 #4

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

Similar topics

3
3937
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 changes. I made a winforms application that allows me to manage those databases easily, and used several SqlDataAdapter to achieve this, all of them filling the same Dataset which has relations, and this Dataset being the DataSource of a...
3
1728
by: Tom Luetz II | last post by:
I'm having some trouble with the DataAdapter in my code. When the parameter in an OleDbCommand, which is created as having a type of OleDbType.Decimal, is set to System.DbNull, the actual value posted to the database upon execution of the Insert command is a floating point value of zero (0.0, actually). The DataAdapter is associated with a DataGrid. When a row is inserted into the grid, the column may contain either nothing "(null)" or...
3
37813
by: Ed | last post by:
Hi, I want to load data to a table in Sql Server from a dataset table in my vb.net app using a dataAdapter. I know how to do this as follows (my question is to see if I can reduce the amount of code below): .... Dim DA As SqlDataAdapter = New SqlDataAdapter Dim Parm As New SqlParameter ....
4
1787
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 you. ====================================== Private Sub SaveChanges(ByVal aContainer As Object)
6
14002
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 = conn da.UpdateCommand.CommandText = "Update tbl1 set fld1 = 'test' where ID = 1" da.Update(tblx) '--tblx/tbl1 not getting updated here.
0
2115
by: webbsk | last post by:
I keep getting an exception when I call the DataAdapter Update method. I have been trying to figure out what is causing the null reference exception for this code for what seems like forever: private void DoInserts(OdbcDataAdapter odbcDataAdapter, string tableName) { DataTable dataTableChanged = dsTapes.Tables.GetChanges(DataRowState.Added);
2
4610
by: mdfayazi | last post by:
I am using dataadapter to Add,Update,Delete rows in a datagridview.Update and delete are working but while adding a rows the problem comes.When I add more than one row only first row values are copied all other rows. Can anybody help me what to do. Dim myBuilder As SqlCommandBuilder = New SqlCommandBuilder(adapterGetBudget) Dim dtdate As Date = Date.Now Dim cmd As New SqlCommand() With cmd .CommandType = CommandType.StoredProcedure
0
1111
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 TABLE1 set FIELD1 = " & value2 & " where FIELD1 = " & value1 return_val = da1.UpdateCommand.ExecuteNonQuery()
2
2898
by: BobLewiston | last post by:
I can read in an SQL table ("Person.Contact") from AdventureWorks and step through it one row at a time, but when I try to save a record, either one I'm inserting or one I'm editting, I get the following exception: Incorrect syntax near ','. Must declare scalar variable "@ContactID". Here's the code: private void btnSave_Click (object sender, EventArgs e) { DataRow row = dataTable.Rows ; ...
0
9618
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10260
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10101
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10038
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9906
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5354
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5482
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4007
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3609
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.