difference between dataAdapter.InsertCommand/dataAdapter.SelectCom

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Rich

    #1

    difference between dataAdapter.InsertCommand/dataAdapter.SelectCom

    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
  • Rich

    #2
    RE: difference between dataAdapter.Ins ertCommand/dataAdapter.Sel ectCom

    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

    Comment

    • Bart Mermuys

      #3
      Re: difference between dataAdapter.Ins ertCommand/dataAdapter.Sel ectCom

      Hi,

      "Rich" <Rich@discussio ns.microsoft.co mwrote in message
      news:8089CC56-ED65-48A5-AC1F-3CD991AAC4B0@mi crosoft.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

      Comment

      • Brian Tkatch

        #4
        Re: difference between dataAdapter.Ins ertCommand/dataAdapter.Sel ectCom

        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.

        Comment

        Working...