PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
DataAdapter-VBForums
Results 1 to 2 of 2

Thread: DataAdapter

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2018
    Posts
    3

    DataAdapter

    Hello All
    I'm a new in SQL and in vba here is my code snippet , can someone explain me how emboldened part works? Why does it needs those two parameters (sql, con)
    Thanks in advance

    Code:
    Dim da As OleDb.OleDbDataAdapter
            Dim sql As String = Nothing
            dbProvider = "PROVIDER=Microsoft.Jet.OLEDB.4.0;"
            TheDatabase = "/AddressBook.mdb"
            MyDocumentsFolder = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
            FullDatabasePath = MyDocumentsFolder & TheDatabase
            dbSource = "Data Source  = " & FullDatabasePath
            con.ConnectionString = dbProvider & dbSource
            con.Open()
            MessageBox.Show("Database is now open")
            sql = "SELECT * FROM tblContacts"
            da = New OleDb.OleDbDataAdapter(sql, con)
            da.Fill(ds, "AdressBook")
            con.Close()
            MessageBox.Show("Database is now Closed")
            txtFirsName.Text = ds.Tables("AdressBook").Rows(0).Item(1)
            txtSureName.Text = ds.Tables("AdressBook").Rows(0).Item(2)
    Last edited by Haake; Mar 6th, 2018 at 09:44 AM.

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    100,631

    Re: DataAdapter

    Quote Originally Posted by Haake View Post
    I'm a new in SQL and in vba here is my code snippet
    Your level of experience in VBA isn't really relevant, given that this is VB.NET code.

    This line:
    vb.net Code:
    1. da = New OleDb.OleDbDataAdapter(sql, con)
    is creating a new data adapter object. A data adapter is an object that basically groups the CRUD operations for a database table. The SelectCommand contains the SQL code to retrieve data from the database and it gets executed when you call the Fill method. The InsertCommand, UpdateCommand and DeleteCommand contain the SQL to save changes back to the database and are executed as needed when you call the Update method. That line of code is functionality equivalent to this:
    vb.net Code:
    1. Din command As New OleDbCommand
    2.  
    3. command.CommandText = sql
    4. command.Connection = con
    5.  
    6. da = New OleDbDataAdapter
    7. da.SelectCommand = command
    When you call Fill, the SQL code gets executed, the result set is retrieved and populates the specified DataTable. Note that there is actually no point explicitly opening and closing the connection in this case because it would be done implicitly by the Fill method.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width