|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
difference between dataAdapter.InsertCommand/dataAdapter.SelectComdataAdapter.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 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. Show quoteHide quote "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 Hi,
"Rich" <R***@discussions.microsoft.com> wrote in message DataAdapter.Update(DataTable) will use UpdateCommand for each row that is news:8089CC56-ED65-48A5-AC1F-3CD991AAC4B0@microsoft.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. 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 Show quoteHide quote > > 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 Rich wrote:
Show quoteHide quote > What is the diffeence bewtween a dataAdapter.InsertCommand and The DataAdapter is meant to make a DataGrid work like it was a real> 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 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.
update database through SQL script
Passing values to another web page Re-size label text how to capture enter key without affrecting copy paste kcust keys max length for tooltip remove xml file root tag Get the value of a cell when row changes in DataGridView add xml validation schema in the xml file remove xml file namespace attribute add xml version line before xml file root node |
|||||||||||||||||||||||