Implimenting update method on VB.Net Application

Jan 8 2009 3:18 AM
I am trying to get the update method to update data in datebase using a datagrid in VB.Net application. The code I have placed compiles but the data does not update. If anyone can please point me in the right direction in what it is I am doing wrong. Please help! I have posted the code below.

Imports System.Data
Imports System.Data.OleDb

Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'BowlingDataSet.Bowl' table. You can move, or remove it, as needed.
        Me.BowlTableAdapter.Fill(Me.BowlingDataSet.Bowl)
        Dim connString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\bowling.mdb"
        Dim myConnection As OleDbConnection = New OleDbConnection
        myConnection.ConnectionString = connString
        ' create a data adapter
        Dim da As OleDbDataAdapter = New OleDbDataAdapter("Select * from Bowl", myConnection)
        ' create a new dataset
        Dim ds As DataSet = New DataSet
       
        da.Fill(ds, "Bowl")
       
        DataGridView1.DataSource = ds.DefaultViewManager
        Me.BowlTableAdapter.Fill(Me.BowlingDataSet.Bowl)


    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    End Sub
    Public Function CreateCommandAndUpdate( _
        ByVal connectionString As String, _
        ByVal queryString As String) As DataSet

        Dim dataSet As DataSet = New DataSet

        Using connection As New OleDbConnection(connectionString)
            connection.Open()
            Dim adapter As New OleDbDataAdapter()

            adapter.SelectCommand = New OleDbCommand( _
                queryString, connection)

            Dim builder As OleDbCommandBuilder = _
                New OleDbCommandBuilder(adapter)

            adapter.Fill(dataSet)

           
            builder.GetUpdateCommand()
            adapter.Update(dataSet)
        End Using
        Return dataSet
    End Function
End Class

Answers (1)