.Net 2.0 Autogenerate update command parameters from a disconnected datatable

  • Thread starter Thread starter david00001
  • Start date Start date
D

david00001

I am trying to find code to generate the command parameters for
updating a datatable (of changes received from UI layer) in a middle
layer object. I want to use a dataadaptor to do the update.
I can easily generate the update, insert and delete sqls for the
command objects, but there seems to be a complete disconnect between
the column datatype info available from the datatable and the
Sqlparameter objects required to create the command objects.

For example, I know the source column name from the database that I
want to update back to, and I know what column in the datatable is the
data required. How do I work out that the string column from the
datatable requires a SqlDbType.VarChar with length of 60 ie varchar(60)
without going back to the database and querying system tables? Surely
the info must be availble somewhere in the datatable schema? How do I
get it?
This is very frustrating. All the sample code I can find is either the
usual kiddy code that assumes you only do simple things with these very
complex objects or so abstract that its useless to someone of
relatively normal intelligence.

Any help would be very greatly appreciated.
Thankyou
 
david00001 said:
I am trying to find code to generate the command parameters for
updating a datatable (of changes received from UI layer) in a middle
layer object. I want to use a dataadaptor to do the update.
I can easily generate the update, insert and delete sqls for the
command objects, but there seems to be a complete disconnect between
the column datatype info available from the datatable and the
Sqlparameter objects required to create the command objects.

For example, I know the source column name from the database that I
want to update back to, and I know what column in the datatable is the
data required. How do I work out that the string column from the
datatable requires a SqlDbType.VarChar with length of 60 ie
varchar(60) without going back to the database and querying system
tables? Surely the info must be availble somewhere in the datatable
schema? How do I get it?
This is very frustrating. All the sample code I can find is either the
usual kiddy code that assumes you only do simple things with these
very complex objects or so abstract that its useless to someone of
relatively normal intelligence.

You might check into a code generator, where the metadata is provided for
you and you can write your own custom templates.

http://www.mygenerationsoftware.com
 
Check the link in my signature below. Makes it much
easier to use an OOP approach.

--
Robbe Morris - 2004-2006 Microsoft MVP C#
I've mapped the database to .NET class properties and methods to
implement an multi-layered object oriented environment for your
data access layer. Thus, you should rarely ever have to type the words
SqlCommand, SqlDataAdapter, or SqlConnection again.
http://www.eggheadcafe.com/articles/adonet_source_code_generator.asp
 
Back
Top