Problem updating a dataset within a button click handler

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

    Problem updating a dataset within a button click handler

    I am relatively new to Visual Basic 2005 Express Edition.
    I am trying to create a simple program that:

    1. Creates and populates a dataset in the form_load handler
    2. Transfers control to a new form to input user changes to the data in a
    Button2_Click event handler
    3. returns control to the Button2_Click event handler to perform the dataset
    update

    However it can’t find the data adapter ‘custDA’ to perform the update in the
    Button2_Click event handler.

    Can anybody help please.

    Many thanks.

    Southcoaster.


    Imports System.Data.Sql Client
    Public Class MainCustomerSel ectionForm

    Dim custDS As DataSet = New DataSet("Custom erSelection")
    Dim CustomerRecordF orm As New CustomerRecordF orm

    Private Sub Form1_Load(ByVa l sender As Object, ByVal e As
    System.EventArg s) Handles Me.Load

    Dim builder As New System.Data.Sql Client.SqlConne ctionStringBuil der
    builder("Data Source") = ".\SQLEXPRE SS"
    builder("Attach DBFilename") = "C:\SQL Server 2000 Sample
    Databases\NORTH WND.MDF"
    builder("Integr ated Security") = True
    builder("Connec t Timeout") = 30
    builder("User Instance") = True

    Dim nwindConn As New SqlConnection()
    nwindConn.Conne ctionString = builder.Connect ionString

    Dim custDA As SqlDataAdapter = New SqlDataAdapter( "SELECT * FROM Customers",
    nwindConn)


    nwindConn.Open( )

    custDA.Fill(cus tDS, "Customers" )


    Me.DataGridView 1.DataSource = custDS
    Me.DataGridView 1.DataMember = "Customers"

    End Sub

    Private Sub Button2_Click(B yVal sender As System.Object, ByVal e As
    System.EventArg s) Handles Button2.Click

    CustomerRecordF orm.ShowDialog( )

    *** ERROR OCCURS HERE AS THE COMPILER CANNOT FIND ‘CustDA’ ***

    custDA.Update(c ustDS, "Customers" )

    End Sub

    End Class


Working...