-
1 Attachment(s)
DataTable creator
The purpose for this simple utility is to create DataTable Columns and avoid having to type in all the properties associated with creating a DataTable. I kept it simple which means use it to create the columns, do not try it fool it as there is no exception handling.
The first iteration created columns, current iteration permits simple DataColumn Expressions with minimal assertion. Currently working on adding functionality to add mocked data with common fields such as first/last name, address along with mocked credit card numbers and mocked SSN.
Requires VS2012 but if you are comfortable with how to downgrade to VS2010 the code is compatible as are the forms.
MSDN article with VS2012 solution. I did not upload it here as a) wanted to maintain the code in one location b) new changes are coming and will post them here.
Attachment 103603
-
Re: DataTable creator
Pretty nifty! Replying so I can easily find it when I get home.
-
Re: DataTable creator
I usually jsut subscribe to threads for that reason... good stuff... apparently I gotta spread the love a little more though...
-tg
-
Re: DataTable creator
I just updated the utility to include an option to create one to four events (common events used).
Example that created events and one column expression
Code:
Public Module DataTable_GeneratedCode
Public Sub Generated()
Dim dt As New DataTable With {.TableName = "MyTable"}
dt.Columns.Add(New DataColumn With {.ColumnName = "Identifier", .DataType = GetType(Int32),
.AutoIncrement = True, .AutoIncrementSeed = 1})
dt.Columns.Add(New DataColumn With {.ColumnName = "FirstName", .DataType = GetType(String)})
dt.Columns.Add(New DataColumn With {.ColumnName = "LastName", .DataType = GetType(String)})
dt.Columns.Add(New DataColumn With {.ColumnName = "FullName", .DataType = GetType(String),
.Expression = "FirstName + ' ' + LastName"})
dt.Columns.Add(New DataColumn With {.ColumnName = "Country", .DataType = GetType(String)})
AddHandler dt.ColumnChanged, AddressOf dt_ColumnChanged
AddHandler dt.ColumnChanging, AddressOf dt_ColumnChanging
AddHandler dt.RowChanging, AddressOf dt_RowChanging
End Sub
Private Sub dt_ColumnChanged(sender As Object, e As DataColumnChangeEventArgs)
End Sub
Private Sub dt_ColumnChanging(sender As Object, e As DataColumnChangeEventArgs)
End Sub
Private Sub dt_RowChanging(sender As Object, e As DataRowChangeEventArgs)
End Sub
End Module