DataAdapter and Dataset Scope

  • Thread starter Thread starter Wayne Wengert
  • Start date Start date
W

Wayne Wengert

I have a Winform in VSNET 2003 where I define a dataadapter and fill a
dataset in the form load event. When a user clicks on a "Save" button I want
to do some validation, save updated values to the dataset and then do an
update to the DA to update the database.

Since the adapter and dataset are defined inside the form load event and
since it won't let me define them as Public or Friend I have no way to
reference them in a Click event.

How should that be set up?

Wayne
 
You can't define them as public or friend *inside* the form load - since
this wouldn't make any sense - the scope of the variables is just that
method anyway. You have to define them *outside* the form load, in order to
make it available in any function in the class.
 
Where can I put this code? I tried putting it in the form Class but it won't
accept it there? The code to setup the adapter and dataset is as follows:

strSQL = "SELECT * FROM Names Where ((Names.NameID) = " & intSelectedID & ")
"

Dim da As New SqlDataAdapter(strSQL, cn)

Dim ds As New DataSet


Wayne
 
You can declare the variables in the form. I would then recommend
instantiating them in the constructor or form load.
 
Marina;

Thanks for the assistance here. I am not experienced with OO so I am
confused. If I put the DIMs for da and ds in the form class and then create
an instance in the Form Load I need to be able to refer to the instance
don't I? That is Private.

Wayne
 
I'm sorry, I don't really understand your question.

It sounds like you should read up on the basics of OO and scope before
proceeding too much with the data access stuff though.
 
Back
Top