Hello everyone.
After a lot of trial and mostly errors with the VS generated Typed DataSets
I decided to make myself one.
I would like you to comment on what things should I add/modify (and why). I
made a sloppy program that generates the classes given a database but for
now I'm not interested in the generator, the generated classes are the focus
of my attention right now.
Here's an example of how my typed tables work:
- Let's say we have the tables Cities and Stores
Cities (City_ID, City_Name)
Stores (Store_ID, Store_Name, Store_City_ID, Store_Address)
http://www.manueldeleon.com/wrapper/createtables.sql
--------------------
Here's a few examples of how to use the Cities and Stores classes:
'The class accepts a Connection String or a SQLConnection object or a
Transaction
Dim strCnn As String = "My connection string."
'1) Get a store information knowing it's ID
Dim myStore As TestDB.StoresRow = TestDB.StoresTable.GetRows(strCnn,
"Store_ID=1")(0)
Dim si As String = myStore.Store_ID & vbCrLf
si &= myStore.Store_Name & vbCrLf
si &= myStore.Store_Address
'The StoresRow knows which city it belongs to,
'therefore we can get the city row and extract the city name instead of just
the Store_City_ID
si &= myStore.Get_CitiesRow.City_Name & vbCrLf
'2.1) Modify the name of the store in one step.
myStore.Update_Store_Name("MyNewName")
'2.2) Modify the name and the address and commit both at once.
myStore.Store_Name = "MyNewName"
myStore.Store_Address = "InTheMiddleOfNowhere"
myStore.UpdateAllFields()
'3) Get all stores in a city.
Dim myCity As TestDB.CitiesRow = TestDB.CitiesTable.GetRows(strCnn,
"City_ID=1")(0)
Dim cStore As TestDB.StoresRow
For Each cStore In myCity.Get_StoresRows
Dim StoreName As String = cStore.Store_Name
Next
'4) Check if a store with the name "MyNewName" exists
Dim StoreDoesExist As Boolean = TestDB.StoresTable.Exists(strCnn,
"Store_Name='MyNewName'")
'5) Delete a store.
TestDB.StoresTable.Delete(strCnn, "Store_ID=666")
'6) Add a new store
Dim myNewStore As TestDB.StoresRow = TestDB.StoresTable.AddNew(strCnn, 2,
"RockPlace", 1)
--------------------
- Generating the classes is a 2 step process (which can be done in one shot
of course)
1) Create an xml file with the table information
http://www.manueldeleon.com/wrapper/tablestocreate.xml
2) Create the classes.
http://www.manueldeleon.com/wrapper/testdb.zip
- To use it add the SQLHelper class to the project
http://download.microsoft.com/downlo...ationBlock.msi
or
http://www.manueldeleon.com/wrapper/sqlhelper.zip
Thank you for your time and comments,
Manuel