[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>&nbsp;</DIV>
<DIV>**************Part 1 (Real noob question)***************</DIV>
<DIV>Eric,</DIV>
<DIV>&nbsp;</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>&nbsp;</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>&nbsp;</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>&nbsp;</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>&nbsp;</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>&nbsp;</DIV>
<DIV>**************Part 2 (ADO and mono)***************</DIV>
<DIV>Eric,</DIV>
<DIV>&nbsp;</DIV>
<DIV>(I did not notice that both questions came from you at first)</DIV>
<DIV>&nbsp;</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).&nbsp; 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>&nbsp;</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>&nbsp;</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>&nbsp;</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&nbsp; 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>&nbsp;</DIV>
<DIV>I hope this helps some and you get a better understanding from =
everyone's comments.</DIV>
<DIV>&nbsp;</DIV>
<DIV>Richard Norman</DIV>
<DIV>Web/Application Developer</DIV>
<DIV>&nbsp;</DIV>
<DIV><A href=3D"http://www.jazzynupe.net/blog/">http://www.jazzynupe.net/bl=
og/</A></DIV>
<DIV>&nbsp;</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>&nbsp;</DIV>
<DIV>**************End of Part 2***************<BR>&gt;&gt;&gt; mono-list-r=
equest@lists.ximian.com 10/20/2004 1:18:02 AM &gt;&gt;&gt;<BR></DIV>
<DIV style=3D"COLOR: #000000"><BR>Message: 8<BR>Cc: mono-list &lt;mono-list=
@lists.ximian.com&gt;<BR>From: Nick Loeve &lt;mono@trickie.org&gt;<BR>Subje=
ct: Re: [Mono-list] Real noob question!<BR>Date: Wed, 20 Oct 2004 14:03:34 =
+1000<BR>To: Eric Damron &lt;edamron@spamcop.net&gt;<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>&gt; Okay, =
I've been doing everything wrong.&nbsp; I've been trying to put some =
<BR>&gt; of my program logic into the main method of one of my classes and =
have <BR>&gt; been fighting it all the way!<BR>&gt;<BR>&gt; What is the =
correct way to structure the class that kicks off the <BR>&gt; whole =
thing?&nbsp; Are you really suppose to create an instance of the <BR>&gt; =
class within the class itself??<BR>&gt;<BR>&gt; public class foo<BR>&gt; =
{<BR>&gt;&nbsp;&nbsp;&nbsp; int somevariables;<BR>&gt;&nbsp;&nbsp;&nbsp; =
AnotherClass&nbsp;&nbsp; anotherClass&nbsp;&nbsp; =3D new AnotherClass();<B=
R>&gt;<BR>&gt;&nbsp;&nbsp;&nbsp; public foo()<BR>&gt;&nbsp;&nbsp;&nbsp; =
{<BR>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // this is a constructor<BR>&=
gt;&nbsp;&nbsp;&nbsp; }<BR>&gt;<BR>&gt;&nbsp;&nbsp;&nbsp; private =
foo2()<BR>&gt;&nbsp;&nbsp;&nbsp; {<BR>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp; // this is a method of class foo<BR>&gt;&nbsp;&nbsp;&nbsp; }<BR>&gt;<BR=
>&gt;&nbsp;&nbsp;&nbsp; static void main()<BR>&gt;&nbsp;&nbsp;&nbsp; =
{<BR>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // here is where I get into =
trouble<BR>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; foo f =3D new =
foo();&nbsp;&nbsp; // Instanating a class within itself is too <BR>&gt; =
wierd!<BR>&gt;&nbsp;&nbsp;&nbsp; }<BR>&gt; }<BR>&gt;<BR>&gt;<BR>&gt; Since =
everything seems to have to be inside a class, the code that <BR>&gt; must =
first execute must also be in a class but how can it execute <BR>&gt; =
unless there is an instance of the class?&nbsp; How can there be an =
<BR>&gt; instance of the class if no code can execute???&nbsp; It's the =
chicken or <BR>&gt; the egg problem!<BR>&gt; ______________________________=
_________________<BR>&gt; Mono-list maillist&nbsp; -&nbsp; Mono-list@lists.=
ximian.com<BR>&gt; <A href=3D"http://lists.ximian.com/mailman/listinfo/mono=
-list">http://lists.ximian.com/mailman/listinfo/mono-list</A><BR>&gt;<BR><B=
R><BR>--__--__--<BR><BR>Message: 9<BR>From: "Hector Geraldino" &lt;hector@c=
lubdelphi.com&gt;<BR>To: "Eric Damron" &lt;edamron@spamcop.net&gt;,<BR>&nbs=
p;&nbsp;&nbsp; "mono-list" &lt;mono-list@lists.ximian.com&gt;<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.&nbsp; And, all this, from a disconnected environment.<BR><BR>Got it =
?<BR><BR>----- Original Message -----<BR>From: "Eric Damron" &lt;edamron@sp=
amcop.net&gt;<BR>To: "mono-list" &lt;mono-list@lists.ximian.com&gt;<BR>Sent=
: Tuesday, October 19, 2004 10:11 PM<BR>Subject: Re: [Mono-list] ADO and =
mono<BR><BR><BR>&gt; Thanks Hector.<BR>&gt;<BR>&gt; It's still a bit =
confusing.&nbsp; So what you're saying is that a single<BR>&gt; dataset =
can contain the result of more than one query?&nbsp; Each query<BR>&gt; =
result in its own table?&nbsp; Did I get it right?<BR>&gt;<BR>&gt; My head =
hurts...<BR>&gt;<BR>&gt; Hector Geraldino wrote:<BR>&gt;<BR>&gt; &gt;Hi,<BR=
>&gt; &gt;<BR>&gt; &gt;Maybe a single query can only return a single =
database, but in a Dataset<BR>you<BR>&gt; &gt;can hold more than one table =
(a collection of datatables).&nbsp; Look at the<BR>&gt; &gt;DataSet.Tables.=
Add() method to see how it works.<BR>&gt; &gt;<BR>&gt; &gt;You migth ask =
"why have more than one datatable in a dataset", and if you<BR>&gt; =
&gt;visit the topic about relationships between tables, you'll find that =
you<BR>can<BR>&gt; &gt;create a complete (pseudo-complete) RDBMS with a =
great characteristic:<BR>it's<BR>&gt; &gt;absolutely disconnected.<BR>&gt; =
&gt;<BR>&gt; &gt;hectorG<BR>&gt; &gt;----- Original Message -----<BR>&gt; =
&gt;From: "Eric Damron" &lt;edamron@spamcop.net&gt;<BR>&gt; &gt;To: =
"mono-list" &lt;mono-list@lists.ximian.com&gt;<BR>&gt; &gt;Sent: Tuesday, =
October 19, 2004 7:48 PM<BR>&gt; &gt;Subject: Re: [Mono-list] ADO and =
mono<BR>&gt; &gt;<BR>&gt; &gt;<BR>&gt; &gt;<BR>&gt; &gt;<BR>&gt; &gt;&gt;Th=
anks for the reply Morten.&nbsp; I guess what confused me was that =
the<BR>&gt; &gt;&gt;author used the same name for the recordset return =
table as the table he<BR>&gt; &gt;&gt;was querying.<BR>&gt; &gt;&gt;<BR>&gt=
; &gt;&gt;I'm still a little confused because the next thing he does =
is:<BR>&gt; &gt;&gt;<BR>&gt; &gt;&gt;DataTable dataTable =3D ds.Tables[0];<=
BR>&gt; &gt;&gt;<BR>&gt; &gt;&gt;If a single recordset table is returned =
isn't the [0] redundant?&nbsp; How<BR>&gt; &gt;&gt;can one return more =
than a single recordset table?<BR>&gt; &gt;&gt;<BR>&gt; &gt;&gt;Thanks<BR>&=
gt; &gt;&gt;_______________________________________________<BR>&gt; =
&gt;&gt;Mono-list maillist&nbsp; -&nbsp; Mono-list@lists.ximian.com<BR>&gt;=
 &gt;&gt;<A href=3D"http://lists.ximian.com/mailman/listinfo/mono-list">htt=
p://lists.ximian.com/mailman/listinfo/mono-list</A><BR>&gt; &gt;&gt;<BR>&gt=
; &gt;&gt;<BR>&gt; &gt;<BR>&gt; &gt;<BR>&gt; &gt;<BR>&gt; &gt;<BR>&gt;<BR>&=
gt; _______________________________________________<BR>&gt; Mono-list =
maillist&nbsp; -&nbsp; Mono-list@lists.ximian.com<BR>&gt; <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__=--