[Mono-list] Real noob question & ADO and mono
Richard Norman
normri@samc.com
Wed, 20 Oct 2004 10:39:47 -0700
This is a MIME message. If you are reading this text, you may want to
consider changing to a mail reader or gateway that understands how to
properly handle MIME multipart messages.
--=__Part0E2E34F3.0__=
Content-Type: text/plain;
charset=us-ascii
Content-Transfer-Encoding: 7bit
I love these kind of questions. :-)
**************Part 1 (Real noob question)***************
Eric,
While I have not seen it done the way you suggest, I believe it can be
done. (I have not tested it, but Visual Studio does not show any initial
problems through Intelisense)
Typically what you see is that one class holds a definition of
something and the class with the "void static main" is just used to
start and call logic as needed. So typically the situation you describe
does not happen often.
What is typically done is that the (using your example) foo class is
instantiated by something else and then those other methods and members
are used. within foo.
Static makes the class not need to be instantiated to use the method,
but then you have no access to member variables or functions that are
not also static. That is where your "foo f=new foo()" comes in. Once
instantiated , the non-static methods are available and you would be
working on an actual instance of the class. So all the other items are
then created and are available through the "f" instance you new'ed.
I hope this explains some of it to you (and I did not just confuse you
more)...
**************End of Part 1***************
**************Part 2 (ADO and mono)***************
Eric,
(I did not notice that both questions came from you at first)
Datasets are basically objects to hold information from databases. What
some people like to do is to create their own objects to hold data from
the database. Datasets are similar except they are created like a
database that is a copy of what you have on the database server.
Datasets don't care what database the data comes from (that's the job of
the data adapters). So if you need to do an application quickly and
don't have massive amounts of time to create your own data objects,
DataSets are perfect to do this job for you.
So what you can do is create a data adapter that connects to SQL server
and save some information from one table (customers). Then say your
sales records are in a MySQL database. you can use a data adapter for
MySQL that will then import that sales data to your sales table (sales).
What you can then do in the dataset that you could not do before is
create a new relationship between these tables in the dataset that says
these sales (from MySQL) are linked to these customers (from SQL
Server). Make changes and deletes and updates. When you are all done
(through the right data adapters) you can push those updates back to the
server.
So essentially DataSets are good for passing objects between tiers of
applications. Typed datasets are the same thing but taken a step
further. They derive from the DataSet class and have "type safe" methods
to access the tables and fields of the database. For example instead of
using ds.Tables["Customers"] or ds.Tables[0] for the customer table
above, you can do this ds.Customers to access the table. It just
improves the readability and reliability getting the right data and
right types from the dataset. If you try to insert the wrong type, it is
a compile time error and not a runtime error.
Also another useful thing you get from a typed dataset is the ability
to do something like this ds.Customers.Rows[0].SalesRows you get
returned the sales rows associated with that particular customer. Again
this is all "disconnected" from the database itself. There is overhead
involved with this, creating all the various row, relationship, and
constraint objects do cost some time (especially if you have a lot of
rows), but this saves you time form doing similar objects yourself. But
if you have the time to create the objects, you should cause you can
optimize it for yourself and only create the objects you need to
create.
I hope this helps some and you get a better understanding from
everyone's comments.
Richard Norman
Web/Application Developer
http://www.jazzynupe.net/blog/
P.S. I may be a little late to the conversation and you may already
understand this, please don't hesitate to ask. The beauty of .NET is
that .NET is pretty much the same everywhere regardless of the language
and syntax.
**************End of Part 2***************
>>> mono-list-request@lists.ximian.com 10/20/2004 1:18:02 AM >>>
Message: 8
Cc: mono-list <mono-list@lists.ximian.com>
From: Nick Loeve <mono@trickie.org>
Subject: Re: [Mono-list] Real noob question!
Date: Wed, 20 Oct 2004 14:03:34 +1000
To: Eric Damron <edamron@spamcop.net>
Eric,
you code would work ok.
It is funny to start with, but the main method is static, so it isn't
called as a method on a class instance.
The main method is often very procedural in nature and often has some
sort of control loop (in a GUI this is hidden in what is called the
event loop).
I often just make a class with only a main method in it just to
separate out the program entry point.
On 20/10/2004, at 1:36 PM, Eric Damron wrote:
> Okay, I've been doing everything wrong. I've been trying to put some
> of my program logic into the main method of one of my classes and
have
> been fighting it all the way!
>
> What is the correct way to structure the class that kicks off the
> whole thing? Are you really suppose to create an instance of the
> class within the class itself??
>
> public class foo
> {
> int somevariables;
> AnotherClass anotherClass = new AnotherClass();
>
> public foo()
> {
> // this is a constructor
> }
>
> private foo2()
> {
> // this is a method of class foo
> }
>
> static void main()
> {
> // here is where I get into trouble
> foo f = new foo(); // Instanating a class within itself is
too
> wierd!
> }
> }
>
>
> Since everything seems to have to be inside a class, the code that
> must first execute must also be in a class but how can it execute
> unless there is an instance of the class? How can there be an
> instance of the class if no code can execute??? It's the chicken or
> the egg problem!
> _______________________________________________
> Mono-list maillist - Mono-list@lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-list
>
--__--__--
Message: 9
From: "Hector Geraldino" <hector@clubdelphi.com>
To: "Eric Damron" <edamron@spamcop.net>,
"mono-list" <mono-list@lists.ximian.com>
Subject: Re: [Mono-list] ADO and mono
Date: Wed, 20 Oct 2004 01:03:48 -0500
Yeah, something like that.
Think that DataSet is some sort of friendly-tables wich lives in the
same
building. No matter where they has come from, no matter if they're
related
or not to each other (in practice, they should), but they could live
together in the same DataSet. The dataset could generate an schema with
all
those tables, their relationship (the datarelation you've defined into
the
dataset), and also when you insert/delete records from/to these tables,
if
they're related or have any rule (like primary key, unique field,
foreign
key etc) the DataSet could throw different exceptions accordly to the
operation. And, all this, from a disconnected environment.
Got it ?
----- Original Message -----
From: "Eric Damron" <edamron@spamcop.net>
To: "mono-list" <mono-list@lists.ximian.com>
Sent: Tuesday, October 19, 2004 10:11 PM
Subject: Re: [Mono-list] ADO and mono
> Thanks Hector.
>
> It's still a bit confusing. So what you're saying is that a single
> dataset can contain the result of more than one query? Each query
> result in its own table? Did I get it right?
>
> My head hurts...
>
> Hector Geraldino wrote:
>
> >Hi,
> >
> >Maybe a single query can only return a single database, but in a
Dataset
you
> >can hold more than one table (a collection of datatables). Look at
the
> >DataSet.Tables.Add() method to see how it works.
> >
> >You migth ask "why have more than one datatable in a dataset", and
if you
> >visit the topic about relationships between tables, you'll find that
you
can
> >create a complete (pseudo-complete) RDBMS with a great
characteristic:
it's
> >absolutely disconnected.
> >
> >hectorG
> >----- Original Message -----
> >From: "Eric Damron" <edamron@spamcop.net>
> >To: "mono-list" <mono-list@lists.ximian.com>
> >Sent: Tuesday, October 19, 2004 7:48 PM
> >Subject: Re: [Mono-list] ADO and mono
> >
> >
> >
> >
> >>Thanks for the reply Morten. I guess what confused me was that
the
> >>author used the same name for the recordset return table as the
table he
> >>was querying.
> >>
> >>I'm still a little confused because the next thing he does is:
> >>
> >>DataTable dataTable = ds.Tables[0];
> >>
> >>If a single recordset table is returned isn't the [0] redundant?
How
> >>can one return more than a single recordset table?
> >>
> >>Thanks
> >>_______________________________________________
> >>Mono-list maillist - Mono-list@lists.ximian.com
> >>http://lists.ximian.com/mailman/listinfo/mono-list
> >>
> >>
> >
> >
> >
> >
>
> _______________________________________________
> Mono-list maillist - Mono-list@lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-list
--=__Part0E2E34F3.0__=
Content-Type: text/html;
charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Description: HTML
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; charset=3Dwindows-125=
2">
<META content=3D"MSHTML 6.00.2900.2523" name=3DGENERATOR></HEAD>
<BODY style=3D"MARGIN: 4px 4px 1px; FONT: 10pt Tahoma">
<DIV>I love these kind of questions. :-)</DIV>
<DIV> </DIV>
<DIV>**************Part 1 (Real noob question)***************</DIV>
<DIV>Eric,</DIV>
<DIV> </DIV>
<DIV>While I have not seen it done the way you suggest, I believe it can =
be done. (I have not tested it, but Visual Studio does not show any =
initial problems through Intelisense)</DIV>
<DIV> </DIV>
<DIV>Typically what you see is that one class holds a definition of =
something and the class with the "void static main" is just used to start =
and call logic as needed. So typically the situation you describe does not =
happen often.</DIV>
<DIV> </DIV>
<DIV>What is typically done is that the (using your example) foo class is =
instantiated by something else and then those other methods and members =
are used. within foo.</DIV>
<DIV> </DIV>
<DIV>Static makes the class not need to be instantiated to use the method, =
but then you have no access to member variables or functions that are not =
also static. That is where your "foo f=3Dnew foo()" comes in. Once =
instantiated , the non-static methods are available and you would be =
working on an actual instance of the class. So all the other items are =
then created and are available through the "f" instance you new'ed.</DIV>
<DIV> </DIV>
<DIV>I hope this explains some of it to you (and I did not just confuse =
you more)...</DIV>
<DIV><BR>**************End of Part 1***************</DIV>
<DIV> </DIV>
<DIV>**************Part 2 (ADO and mono)***************</DIV>
<DIV>Eric,</DIV>
<DIV> </DIV>
<DIV>(I did not notice that both questions came from you at first)</DIV>
<DIV> </DIV>
<DIV>Datasets are basically objects to hold information from databases. =
What some people like to do is to create their own objects to hold data =
from the database. Datasets are similar except they are created like a =
database that is a copy of what you have on the database server. Datasets =
don't care what database the data comes from (that's the job of the data =
adapters). So if you need to do an application quickly and don't =
have massive amounts of time to create your own data objects, DataSets are =
perfect to do this job for you.</DIV>
<DIV> </DIV>
<DIV>So what you can do is create a data adapter that connects to SQL =
server and save some information from one table (customers). Then say your =
sales records are in a MySQL database. you can use a data adapter for =
MySQL that will then import that sales data to your sales table (sales). =
What you can then do in the dataset that you could not do before is create =
a new relationship between these tables in the dataset that says these =
sales (from MySQL) are linked to these customers (from SQL Server). Make =
changes and deletes and updates. When you are all done (through the right =
data adapters) you can push those updates back to the server.</DIV>
<DIV> </DIV>
<DIV>So essentially DataSets are good for passing objects between tiers of =
applications. Typed datasets are the same thing but taken a step further. =
They derive from the DataSet class and have "type safe" methods to access =
the tables and fields of the database. For example instead of using =
ds.Tables["Customers"] or ds.Tables[0] for the customer table above, you =
can do this ds.Customers to access the table. It just improves the =
readability and reliability getting the right data and right types from =
the dataset. If you try to insert the wrong type, it is a compile time =
error and not a runtime error.</DIV>
<DIV> </DIV>
<DIV>Also another useful thing you get from a typed dataset is the ability =
to do something like this ds.Customers.Rows[0].SalesRows you get =
returned the sales rows associated with that particular customer. Again =
this is all "disconnected" from the database itself. There is overhead =
involved with this, creating all the various row, relationship, and =
constraint objects do cost some time (especially if you have a lot of =
rows), but this saves you time form doing similar objects yourself. But if =
you have the time to create the objects, you should cause you can optimize =
it for yourself and only create the objects you need to create.</DIV>
<DIV> </DIV>
<DIV>I hope this helps some and you get a better understanding from =
everyone's comments.</DIV>
<DIV> </DIV>
<DIV>Richard Norman</DIV>
<DIV>Web/Application Developer</DIV>
<DIV> </DIV>
<DIV><A href=3D"http://www.jazzynupe.net/blog/">http://www.jazzynupe.net/bl=
og/</A></DIV>
<DIV> </DIV>
<DIV>P.S. I may be a little late to the conversation and you may already =
understand this, please don't hesitate to ask. The beauty of .NET is that =
.NET is pretty much the same everywhere regardless of the language and =
syntax.</DIV>
<DIV> </DIV>
<DIV>**************End of Part 2***************<BR>>>> mono-list-r=
equest@lists.ximian.com 10/20/2004 1:18:02 AM >>><BR></DIV>
<DIV style=3D"COLOR: #000000"><BR>Message: 8<BR>Cc: mono-list <mono-list=
@lists.ximian.com><BR>From: Nick Loeve <mono@trickie.org><BR>Subje=
ct: Re: [Mono-list] Real noob question!<BR>Date: Wed, 20 Oct 2004 14:03:34 =
+1000<BR>To: Eric Damron <edamron@spamcop.net><BR><BR>Eric,<BR><BR>yo=
u code would work ok.<BR><BR>It is funny to start with, but the main =
method is static, so it isn't <BR>called as a method on a class instance.<B=
R><BR>The main method is often very procedural in nature and often has =
some <BR>sort of control loop (in a GUI this is hidden in what is called =
the <BR>event loop).<BR><BR>I often just make a class with only a main =
method in it just to <BR>separate out the program entry point.<BR><BR><BR><=
BR><BR>On 20/10/2004, at 1:36 PM, Eric Damron wrote:<BR><BR>> Okay, =
I've been doing everything wrong. I've been trying to put some =
<BR>> of my program logic into the main method of one of my classes and =
have <BR>> been fighting it all the way!<BR>><BR>> What is the =
correct way to structure the class that kicks off the <BR>> whole =
thing? Are you really suppose to create an instance of the <BR>> =
class within the class itself??<BR>><BR>> public class foo<BR>> =
{<BR>> int somevariables;<BR>> =
AnotherClass anotherClass =3D new AnotherClass();<B=
R>><BR>> public foo()<BR>> =
{<BR>> // this is a constructor<BR>&=
gt; }<BR>><BR>> private =
foo2()<BR>> {<BR>> &nb=
sp; // this is a method of class foo<BR>> }<BR>><BR=
>> static void main()<BR>> =
{<BR>> // here is where I get into =
trouble<BR>> foo f =3D new =
foo(); // Instanating a class within itself is too <BR>> =
wierd!<BR>> }<BR>> }<BR>><BR>><BR>> Since =
everything seems to have to be inside a class, the code that <BR>> must =
first execute must also be in a class but how can it execute <BR>> =
unless there is an instance of the class? How can there be an =
<BR>> instance of the class if no code can execute??? It's the =
chicken or <BR>> the egg problem!<BR>> ______________________________=
_________________<BR>> Mono-list maillist - Mono-list@lists.=
ximian.com<BR>> <A href=3D"http://lists.ximian.com/mailman/listinfo/mono=
-list">http://lists.ximian.com/mailman/listinfo/mono-list</A><BR>><BR><B=
R><BR>--__--__--<BR><BR>Message: 9<BR>From: "Hector Geraldino" <hector@c=
lubdelphi.com><BR>To: "Eric Damron" <edamron@spamcop.net>,<BR>&nbs=
p; "mono-list" <mono-list@lists.ximian.com><BR>Subject: =
Re: [Mono-list] ADO and mono<BR>Date: Wed, 20 Oct 2004 01:03:48 -0500<BR><B=
R>Yeah, something like that.<BR><BR>Think that DataSet is some sort of =
friendly-tables wich lives in the same<BR>building. No matter where they =
has come from, no matter if they're related<BR>or not to each other (in =
practice, they should), but they could live<BR>together in the same =
DataSet. The dataset could generate an schema with all<BR>those tables, =
their relationship (the datarelation you've defined into the<BR>dataset), =
and also when you insert/delete records from/to these tables, if<BR>they're=
related or have any rule (like primary key, unique field, foreign<BR>key =
etc) the DataSet could throw different exceptions accordly to the<BR>operat=
ion. And, all this, from a disconnected environment.<BR><BR>Got it =
?<BR><BR>----- Original Message -----<BR>From: "Eric Damron" <edamron@sp=
amcop.net><BR>To: "mono-list" <mono-list@lists.ximian.com><BR>Sent=
: Tuesday, October 19, 2004 10:11 PM<BR>Subject: Re: [Mono-list] ADO and =
mono<BR><BR><BR>> Thanks Hector.<BR>><BR>> It's still a bit =
confusing. So what you're saying is that a single<BR>> dataset =
can contain the result of more than one query? Each query<BR>> =
result in its own table? Did I get it right?<BR>><BR>> My head =
hurts...<BR>><BR>> Hector Geraldino wrote:<BR>><BR>> >Hi,<BR=
>> ><BR>> >Maybe a single query can only return a single =
database, but in a Dataset<BR>you<BR>> >can hold more than one table =
(a collection of datatables). Look at the<BR>> >DataSet.Tables.=
Add() method to see how it works.<BR>> ><BR>> >You migth ask =
"why have more than one datatable in a dataset", and if you<BR>> =
>visit the topic about relationships between tables, you'll find that =
you<BR>can<BR>> >create a complete (pseudo-complete) RDBMS with a =
great characteristic:<BR>it's<BR>> >absolutely disconnected.<BR>> =
><BR>> >hectorG<BR>> >----- Original Message -----<BR>> =
>From: "Eric Damron" <edamron@spamcop.net><BR>> >To: =
"mono-list" <mono-list@lists.ximian.com><BR>> >Sent: Tuesday, =
October 19, 2004 7:48 PM<BR>> >Subject: Re: [Mono-list] ADO and =
mono<BR>> ><BR>> ><BR>> ><BR>> ><BR>> >>Th=
anks for the reply Morten. I guess what confused me was that =
the<BR>> >>author used the same name for the recordset return =
table as the table he<BR>> >>was querying.<BR>> >><BR>>=
; >>I'm still a little confused because the next thing he does =
is:<BR>> >><BR>> >>DataTable dataTable =3D ds.Tables[0];<=
BR>> >><BR>> >>If a single recordset table is returned =
isn't the [0] redundant? How<BR>> >>can one return more =
than a single recordset table?<BR>> >><BR>> >>Thanks<BR>&=
gt; >>_______________________________________________<BR>> =
>>Mono-list maillist - Mono-list@lists.ximian.com<BR>>=
>><A href=3D"http://lists.ximian.com/mailman/listinfo/mono-list">htt=
p://lists.ximian.com/mailman/listinfo/mono-list</A><BR>> >><BR>>=
; >><BR>> ><BR>> ><BR>> ><BR>> ><BR>><BR>&=
gt; _______________________________________________<BR>> Mono-list =
maillist - Mono-list@lists.ximian.com<BR>> <A href=3D"http:/=
/lists.ximian.com/mailman/listinfo/mono-list">http://lists.ximian.com/mailm=
an/listinfo/mono-list</A><BR></DIV></BODY></HTML>
--=__Part0E2E34F3.0__=--