By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,064 Members | 1,524 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,064 IT Pros & Developers. It's quick & easy.

Problem updating a dataset within a button click handler

P: n/a
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.SqlClient
Public Class MainCustomerSelectionForm

Dim custDS As DataSet = New DataSet("CustomerSelection")
Dim CustomerRecordForm As New CustomerRecordForm

Private Sub Form1_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load

Dim builder As New System.Data.SqlClient.SqlConnectionStringBuilder
builder("Data Source") = ".\SQLEXPRESS"
builder("AttachDBFilename") = "C:\SQL Server 2000 Sample
Databases\NORTHWND.MDF"
builder("Integrated Security") = True
builder("Connect Timeout") = 30
builder("User Instance") = True

Dim nwindConn As New SqlConnection()
nwindConn.ConnectionString = builder.ConnectionString

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

custDA.Fill(custDS, "Customers")
Me.DataGridView1.DataSource = custDS
Me.DataGridView1.DataMember = "Customers"

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click

CustomerRecordForm.ShowDialog()

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

custDA.Update(custDS, "Customers")

End Sub

End Class
Oct 29 '06 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.