How to save Datatable-VBForums
Results 1 to 2 of 2

Thread: How to save Datatable

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Oct 2013
    Location
    Norco, CA
    Posts
    16

    How to save Datatable

    Name:  Form.jpg
Views: 248
Size:  15.9 KB

    I'm trying to save the entire datatable. The datatable is named DataTableGrid1. Any suggestions why this isnt working.

    Thanks

    Code:
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Dim sql As String
            sql = String.Format("insert * from notes")
            Dim con = db.GetConnection
            Dim cmd As New OleDbCommand(sql, con)
            Dim ds As New DataSet
            Dim da As New OleDbDataAdapter(cmd)
    
    
            'lookup dataset changes
    
    
            da.Update(DataGridView1) 'Fill Dataset with Table data
    
    
        End Sub

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

    Re: How to save Datatable

    It's not working for a number of reasons. I suggest that you follow the CodeBank link in my signature below and check out my thread on Retrieving & Saving Data to see how to use a data adapter and a DataTable. After populating the DataTable, you can bind it to a BindingSource and then bind that to the grid, e.g.
    Code:
    Me.BindingSource1.DataSource = myDataTable
    Me.DataGridView1.DataSource = Me.BindingSource1
    When you're ready to save, call EndEdit on the BindingSource before calling Update on the data adapter.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    MSDN "How Do I?" Videos: VB | C#
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Tags for this Thread

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

Survey posted by VBForums.