Programmatically Create Modules / Classes

CarlMack

New member
Joined
Dec 21, 2006
Messages
4
Programming Experience
Beginner
Hi All,

I am completely new to VB.NET but have a bit of experience in VBA and Dbs. I am using VS2005 with SQL Server 2005 as a back end.

I want to programatically create some classes based on some data in a Db. In VBA I would add a reference to VBA Extensibility and use VBComponents to start creating and writing modules.

I think I will be able to get the data ok but does anybody have any links to material on creating / modifying modules programmatically in .NET ?


Cheers

Carl

I cross posted this http://www.xtremevbtalk.com/showthread.php?p=1206153#post1206153
 
Last edited:
This would be an interesting task in which I may also be curious to learn; but if you don't mind me asking; what are you trying to achieve? There may be a better solution than to create Classes or Modules programmatically. I can't think of any scenarios in my head at the moment where you would have to depend on this type of programming, well none so practical I mean. Unless you are trying to develop software for developers such another IDE or something. I don't know really but if you tell me what you are trying to do myself or the people here on the forum may have an optimal solution rather than what you are trying to do.
 
I looked at the cross-forum post. You can generate schema from a DataTable/Dataset with its WriteXmlSchema method (possibly modify the schema to suit your needs afterwards), the resultant schema file may then be converted to a class with the Xsd.exe utility. Generating a Strongly Typed DataSet
 
ImDaFrEaK,

Appreciate your interest.

We create a tier of data access classes to talk to databases. A base class that performs the connection and then a couple of classes per table that inherit the base class. The top level has a property for each field in the table and methods like READ a record and WRITE a record. I think this is standard practice for many developers and it facilitates quick and neat coding in forms.

The problem is it takes time to write these classes once a the db structure has been completed and more time if changes to the db are made. I have a couple of VB.NET projects coming up and I want to automate this access class writing by connecting to the db and reading its structure. I have done this sort of thing before in VBA for Office devlopment and found it very useful.

Does that make sense ?

JohnH,

Many thanks for the suggestion and link.

Carl
 
This does make since. However; I question this w/o a lot of experience in db projects so forgive me, but I had the understanding that ADO.NET performed much in this manner or am I off in my thinking?
 
Last edited:
Ah.... you're building a in-house ORM --- you do realize there are many out there.... you may want to take a look at myGeneration http://www.mygenerationsoftware.com/portal/default.aspx ... it's got a scripty language built into their engine that allows you to customize the output. I've used it a number of times to build table scripts, abstract classes, concrete classes, and even stored procedures.

-tg
 
Hi ImDaFrEaK,

I am a complete newbie to VB.NET so I am not sure about anything but I am using ADO for the connection in the lower level class it is just that I think it is better to have a class for each table. For example in a form that has all the fields for a record I want to just say TableClass.Field1 = Form.TextBox1 .... TableClass.Write. The lower level will then do all the checking to see if everything is ok and write the record.

TechGnome,

Great link. I downloaded MyGeneration and I am firing off SPs and code as we speak. For VB.NET it seems to use the "brute force" method writing lines as it goes. It looks great. Will it be the final solution ? My head is spinning trying to get to grips with all this so I don't know, but thanks alot.

Carl
 
Carl - I know what you mean, it took me a while to get my head around it as well, but once I got things customized the way I want... it was great...

-tg
 
it took me a while to get my head around it as well,

Well if I ever do I'll pop back and let you know. :) I can envisage the possibilities and it's exciting but it looks like a very long road.

Thanks again.

Carl
 
Back
Top