Last post Sep 18, 2005 05:24 PM by pimpstein
Sep 17, 2005 09:30 AM|pimpstein|LINK
Sep 17, 2005 01:23 PM|JDHill|LINK
Sep 17, 2005 09:03 PM|pimpstein|LINK
Sep 17, 2005 11:49 PM|JDHill|LINK
Sep 18, 2005 09:59 AM|pimpstein|LINK
O.K. Let's just say we have a regular business application... with a database containing customers, invoices, etc.
So, we got the database there, but we have no classes build yet. So I could sit there and create the same exact entities as classes, but their core would be basically the same... like each one is going to have get and set properties that read and write
from a similarly structured table, with respect to its properties, types, etc. But if I could have a base class that all of my classes derive from that goes out and figures out all the fields of the table, and dynamically creates matching properties with
matching get/set statements, that would save me a lot of work and repetitive code.
Sep 18, 2005 03:33 PM|JDHill|LINK
Sep 18, 2005 05:02 PM|pimpstein|LINK
Sep 18, 2005 05:24 PM|JDHill|LINK
1) Create a new Windows Application (WindowsApplication1). Add a Button and a Textbox to Form1.
2) Open the Server Explorer
3) Right-click Data Connections and select Add Connection
4) Use the dialog to connect to your database. The Server Explorer will update showing your database
5) Right-click your project name in the Solution Explorer and select Add New Item
5) Select DataSet (DataSet1.xsd)
6) Drag one of your tables (customers, for this example) onto the DataSet Designer
7) Build the solution
8) Switch back to the Form Designer, and in the Toolbox, under WindowsApplication1 Components you will find components named DataSet1 and customersTableAdapter. Drag these onto your form.
9) Switch to Code View and try something like this (this assumes a 'name' column in the customers table):
Sub Form1_Load(ByVal sender
ByVal e As System.EventArgs)
Sub Button1_Click(ByVal sender
As System.Object, ByVal e
As System.EventArgs) Handles Button1.Click
Sep 18, 2005 05:54 PM|pimpstein|LINK
Sep 18, 2005 06:30 PM|JDHill|LINK
Short answer this time: no.
Inheriting form a 'Dataset.customer' would be inheriting from a property.
I already thought that it was quite concise code. If you wanted to, you could rename your tables using non-plurals for column names like Customer. If you then renamed the DataSet Customers, your code would look much like plain English:
Is that any better?
Sep 18, 2005 07:59 PM|pimpstein|LINK
Sep 19, 2005 02:00 AM|JDHill|LINK
Sep 19, 2005 01:08 PM|pimpstein|LINK