473,406 Members | 2,745 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

DataAdapter and Dataset Scope

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
Nov 20 '05 #1
5 1317
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.

"Wayne Wengert" <wa***************@wengert.com> wrote in message
news:uO**************@tk2msftngp13.phx.gbl...
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

Nov 20 '05 #2
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
"Marina" <so*****@nospam.com> wrote in message
news:ei**************@TK2MSFTNGP10.phx.gbl...
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.

"Wayne Wengert" <wa***************@wengert.com> wrote in message
news:uO**************@tk2msftngp13.phx.gbl...
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


Nov 20 '05 #3
You can declare the variables in the form. I would then recommend
instantiating them in the constructor or form load.

"Wayne Wengert" <wa***************@wengert.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
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
"Marina" <so*****@nospam.com> wrote in message
news:ei**************@TK2MSFTNGP10.phx.gbl...
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.

"Wayne Wengert" <wa***************@wengert.com> wrote in message
news:uO**************@tk2msftngp13.phx.gbl...
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



Nov 20 '05 #4
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

"Marina" <so*****@nospam.com> wrote in message
news:uE**************@TK2MSFTNGP09.phx.gbl...
You can declare the variables in the form. I would then recommend
instantiating them in the constructor or form load.

"Wayne Wengert" <wa***************@wengert.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
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
"Marina" <so*****@nospam.com> wrote in message
news:ei**************@TK2MSFTNGP10.phx.gbl...
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.

"Wayne Wengert" <wa***************@wengert.com> wrote in message
news:uO**************@tk2msftngp13.phx.gbl...
> 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
>
>



Nov 20 '05 #5
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.

"Wayne Wengert" <wa***************@wengert.com> wrote in message
news:e0**************@TK2MSFTNGP09.phx.gbl...
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

"Marina" <so*****@nospam.com> wrote in message
news:uE**************@TK2MSFTNGP09.phx.gbl...
You can declare the variables in the form. I would then recommend
instantiating them in the constructor or form load.

"Wayne Wengert" <wa***************@wengert.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
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
"Marina" <so*****@nospam.com> wrote in message
news:ei**************@TK2MSFTNGP10.phx.gbl...
> 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.
>
> "Wayne Wengert" <wa***************@wengert.com> wrote in message
> news:uO**************@tk2msftngp13.phx.gbl...
> > 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
> >
> >
>
>



Nov 20 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: JJ | last post by:
Hi, I created a DataAdapter, connection object and dataset generated from DataAdapter by dragging DataAdapter compenent to win form. Now in the code behind I want to use that DataAdapter. I go...
13
by: Doug Bell | last post by:
Hi, I thought I had this sorted this morning but it is still a problem. My application has a DataAccess Class. When it starts, it: Connects to a DB (OLE DB) If it connects it uses an...
4
by: astro | last post by:
I would like to build some generic code that is able to figure out the correct dataAdapter to apply changes to given a form with several dataAdapters. Any suggestions on the following? Thank...
8
by: Zorpiedoman | last post by:
I keep getting a concurrency exception the second time I make a change and attempt to update a dataadapter. It appears this is by design, so there must be something I can do to avoid it. ...
0
by: davefromalbury | last post by:
I have a gridview connected to a objectdatasource. Can't for the life of me get it to display anything though, always appears empty. The dataset always seems to be filled with records, as the...
2
by: susan.f.barrett | last post by:
Hi, Despite me being able to type the following in to SQL Server and it updating 1 row: > updatestockcategory 1093, 839 In my code, it is not updating any rows. dataSet = new DataSet();
6
by: Rich | last post by:
Dim da As New SqlDataAdapter("Select * from tbl1", conn) dim tblx As New DataTable da.Fill(tblx) '--works OK up to this point da.UpdateCommand = New SqlCommand da.UpdateCommand.Connection =...
3
by: Fred Chateau | last post by:
Any obvious reason here why data is not being loaded into the database? SqlDataAdapter dataAdapter = new SqlDataAdapter(sqlCommand); SqlCommandBuilder commandBuilder = new...
2
by: =?Utf-8?B?S2V2aW4=?= | last post by:
I am pretty new to C# and .NET and am using VS 2005. Let's assume I have an MDI application with various child windows, each of which will need access to a database. My question is: where would...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.