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
 
 
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***************
>>> [EMAIL PROTECTED] 10/20/2004 1:18:02 AM >>>

Message: 8
Cc: mono-list <[EMAIL PROTECTED]>
From: Nick Loeve <[EMAIL PROTECTED]>
Subject: Re: [Mono-list] Real noob question!
Date: Wed, 20 Oct 2004 14:03:34 +1000
To: Eric Damron <[EMAIL PROTECTED]>

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  -  [EMAIL PROTECTED]
> http://lists.ximian.com/mailman/listinfo/mono-list
>


--__--__--

Message: 9
From: "Hector Geraldino" <[EMAIL PROTECTED]>
To: "Eric Damron" <[EMAIL PROTECTED]>,
    "mono-list" <[EMAIL PROTECTED]>
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" <[EMAIL PROTECTED]>
To: "mono-list" <[EMAIL PROTECTED]>
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" <[EMAIL PROTECTED]>
> >To: "mono-list" <[EMAIL PROTECTED]>
> >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  -  [EMAIL PROTECTED]
> >>http://lists.ximian.com/mailman/listinfo/mono-list
> >>
> >>
> >
> >
> >
> >
>
> _______________________________________________
> Mono-list maillist  -  [EMAIL PROTECTED]
> http://lists.ximian.com/mailman/listinfo/mono-list

Reply via email to