Results 1 to 5 of 5

Thread: OleDbCommand , OleDbDataAdapter

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Feb 2014
    Posts
    169

    OleDbCommand , OleDbDataAdapter

    friends
    this code work with me very very good
    but some thing i can't understand
    why i use OleDbDataAdapter in this code

    this code can work without OleDbDataAdapter
    why in this code
    OleDbDataAdapter
    is added


    Code:
     Try
                cn.Open()
                Dim da As New OleDbDataAdapter
                Dim com As New OleDbCommand
                com.Connection = cn
                com.CommandText = "insert into tblclient (ClientName)values('zzzzzzzzzzzzzzzzzzzzzz')"
                da.InsertCommand = com
                da.InsertCommand.ExecuteNonQuery()
                cn.Close()
            Catch ex As Exception
                MsgBox(ex.Message)
            End Try

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: OleDbCommand , OleDbDataAdapter

    You shouldn't be using a data adapter in that situation. It's pointless. A data adapter is a way to combine four commands that can be used to retrieve data from a database into a DataTable and then save changes from that DataTable back to the database. You call Fill to execute the SelectCommand and then you call Update to execute InsertCommand, UpdateCommand and DeleteCommand.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Feb 2014
    Posts
    169

    Re: OleDbCommand , OleDbDataAdapter

    Quote Originally Posted by jmcilhinney View Post
    You shouldn't be using a data adapter in that situation. It's pointless. A data adapter is a way to combine four commands that can be used to retrieve data from a database into a DataTable and then save changes from that DataTable back to the database. You call Fill to execute the SelectCommand and then you call Update to execute InsertCommand, UpdateCommand and DeleteCommand.
    thank you for your answer;
    []
    Dim da As New OleDbDataAdapter("select * from tblclient", cn)
    Dim dt As New DataTable
    da.Fill(dt)
    [/code]

    i fill data table with OleDbDataAdapter
    how can i delete clientid =1
    how can i edit clientid =5
    how can i insert another client

    thank you very much for you advice and help and time;

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: OleDbCommand , OleDbDataAdapter

    Instead of asking questions on every little thing here, I would suggest that you read a tutorial or two. The VB beginners tutorial link in my signature below includes some information on data access. You might also follow the Database FAQ link and check out some of the .NET resources there.

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Feb 2014
    Posts
    169

    Re: OleDbCommand , OleDbDataAdapter



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width