473,409 Members | 1,943 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,409 software developers and data experts.

difference between dataAdapter.InsertCommand/dataAdapter.SelectCom

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 = New SqlCommand
da.SelectCommand.Connectoin = conn
da.SelectCommand.CommandType = Command.Text
da.SelectCommand.CommandText = "insert Into tbl1 Select * from tbl2"
da.SelectCommand.ExecuteNonQuery

Or

Dim da As SqlDataAdapter
conn.Open
da.InsertCommand = New SqlCommand
da.InsertCommand.Connectoin = conn
da.InsertCommand.CommandType = Command.Text
da.InsertCommand.CommandText = "insert Into tbl1 Select * from tbl2"
da.InsertCommand.ExecuteNonQuery

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 12486
I believe the answer to my question is that you can use the
dataAdapter.Update method with dataAdapter.InsertCommand and
dataAdapter.Update command, but you can only use dataAdapter.Fill with the
dataAdapter.SelectCommand.

Any additional comments appreciated.

"Rich" wrote:
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 = New SqlCommand
da.SelectCommand.Connectoin = conn
da.SelectCommand.CommandType = Command.Text
da.SelectCommand.CommandText = "insert Into tbl1 Select * from tbl2"
da.SelectCommand.ExecuteNonQuery

Or

Dim da As SqlDataAdapter
conn.Open
da.InsertCommand = New SqlCommand
da.InsertCommand.Connectoin = conn
da.InsertCommand.CommandType = Command.Text
da.InsertCommand.CommandText = "insert Into tbl1 Select * from tbl2"
da.InsertCommand.ExecuteNonQuery

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**@discussions.microsoft.comwrote in message
news:80**********************************@microsof t.com...
>I believe the answer to my question is that you can use the
dataAdapter.Update method with dataAdapter.InsertCommand and
dataAdapter.Update command, but you can only use dataAdapter.Fill with the
dataAdapter.SelectCommand.
DataAdapter.Update(DataTable) will use UpdateCommand for each row that is
modified, InsertCommand for each new row and DeleteCommand for each deleted
row.

DataAdapter.Fill(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.ExecuteNonQuery()
HTH,
Greetings

>
Any additional comments appreciated.

"Rich" wrote:
>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 = New SqlCommand
da.SelectCommand.Connectoin = conn
da.SelectCommand.CommandType = Command.Text
da.SelectCommand.CommandText = "insert Into tbl1 Select * from tbl2"
da.SelectCommand.ExecuteNonQuery

Or

Dim da As SqlDataAdapter
conn.Open
da.InsertCommand = New SqlCommand
da.InsertCommand.Connectoin = conn
da.InsertCommand.CommandType = Command.Text
da.InsertCommand.CommandText = "insert Into tbl1 Select * from tbl2"
da.InsertCommand.ExecuteNonQuery

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.InsertCommand and
dataAdapter.SelectCommand (and dataAdapter.UpdateCommand for that matter)?

Dim da As SqlDataAdapter
conn.Open
da.SelectCommand = New SqlCommand
da.SelectCommand.Connectoin = conn
da.SelectCommand.CommandType = Command.Text
da.SelectCommand.CommandText = "insert Into tbl1 Select * from tbl2"
da.SelectCommand.ExecuteNonQuery

Or

Dim da As SqlDataAdapter
conn.Open
da.InsertCommand = New SqlCommand
da.InsertCommand.Connectoin = conn
da.InsertCommand.CommandType = Command.Text
da.InsertCommand.CommandText = "insert Into tbl1 Select * from tbl2"
da.InsertCommand.ExecuteNonQuery

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
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...
3
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...
3
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...
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 =...
0
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: ...
2
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...
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...
2
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...
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: 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
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,...
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.