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