Re: Problem updating a dataset within a button click handler

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Many thanks I will try one of the newsgroups you suggest.

"Ralph" wrote:


"Southcoaster" <Southcoaster@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:D079377B-B081-4D31-8353-8CD4C2723F9B@xxxxxxxxxxxxxxxx
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 IT CANNOT FIND 'CustDA' ***

custDA.Update(custDS, "Customers")

End Sub

End Class


You need to re-post to a dotNet newsgroup to get a wider audience of people
who use it. This news group is populated by programmers who use classic VB
(VB6 and below) and ADO (not ADO.Net, which is a very different critter).

Try...
news://msnews.microsoft.com/
microsoft.public.dotnet.languages.vb
microsoft.public.dotnet.languages.vb.data
microsoft.public.dotnet.framework.adonet
microsoft.public.dotnet.framework.windowsforms.controls
microsoft.public.dotnet.framework.windowsforms.databinding

-ralph




.


Quantcast