PC Review


Reply
Thread Tools Rate Thread

Parameters with DataAdapter commands

 
 
Predrag
Guest
Posts: n/a
 
      17th Mar 2004
Hello.

I have an issues with my data access layer. It should have methods like:
OpenTable(tableName) that returns DataTable and UpdateTable(dataTable,
tableName) that should update, insert and delete rows from the table.
OpenTable method is fine, but the problem is with UpdateTable method. I
decided to build insert, update and delete commands on-fly, and the problem
is with defining parameters' types. Namely, if it's ODBC provider, I need
OdbcParameter that requires OdbcType if it's SQL server, I need SqlDbType.
But, where do I find OdbcType or SqlDbType. After opening the table, DAL
returned DataTable as the result. Later on, this same object will be passed
in UpdateTable method and in DataTable, there are only Columns with DataType
property which is of different type then OdbcType or SqlDbType.

My thoughts, so far, could be summarized in:

1. I noticed that, if I create a parameter and specify as its value DataType
of the column, SqlDbType of the parameter gets the proper type. I don't
understand this, couldn't find anything about it and am afraid to use it.
2. I could do some type of mapping from DataType to SqlDbType (huge
switch/select case)
3. I could derive SqlDataColumn from DataColumn, populate additional Sql
specific fields during opening the table and insert it in DataTable object
(I already did that for ODBC provider, but it doesn't look very nice
(although it works)) The disadvantage is that update will work only with
data tables created with OpenTable method, because it will rely on sql
specific data members.

Any comment is very appreciated.
Thanks a lot.
- Predrag.


 
Reply With Quote
 
 
 
 
David Browne
Guest
Posts: n/a
 
      17th Mar 2004

"Predrag" <(E-Mail Removed)> wrote in message
news:e4HQ5o%(E-Mail Removed)...
> Hello.
>
> I have an issues with my data access layer. It should have methods like:
> OpenTable(tableName) that returns DataTable and UpdateTable(dataTable,
> tableName) that should update, insert and delete rows from the table.
> OpenTable method is fine, but the problem is with UpdateTable method. I
> decided to build insert, update and delete commands on-fly, and the

problem
> is with defining parameters' types. Namely, if it's ODBC provider, I need
> OdbcParameter that requires OdbcType if it's SQL server, I need SqlDbType.
> But, where do I find OdbcType or SqlDbType. After opening the table, DAL
> returned DataTable as the result. Later on, this same object will be

passed
> in UpdateTable method and in DataTable, there are only Columns with

DataType
> property which is of different type then OdbcType or SqlDbType.
>
> My thoughts, so far, could be summarized in:
>
> 1. I noticed that, if I create a parameter and specify as its value

DataType
> of the column, SqlDbType of the parameter gets the proper type. I don't
> understand this, couldn't find anything about it and am afraid to use it.


This is the key. Each provider-specific implementation the parameter class
implements the interface IDataParameter, which has a property
IDataParameter.DbType. Most also have an internal type system like SqlType,
etc. But all are required to map their internal types back and forth from
DbType's and you can just use the IDataParameter.DbType and let each
provider map that to an internal type.

> 2. I could do some type of mapping from DataType to SqlDbType (huge
> switch/select case)


That's already baked into the SqlParameter type.

David


 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
DataAdapter Commands Charles Microsoft ADO .NET 2 15th Feb 2006 09:36 AM
Control References in DataAdapter Commands Christopher Weaver Microsoft C# .NET 4 4th May 2005 08:49 PM
run Insert/Delete DataAdapter commands? Rich Microsoft VB .NET 2 10th Feb 2004 07:59 PM
DataAdapter using commandbuilder's commands, not it's own. Marina Microsoft ADO .NET 1 12th Dec 2003 06:58 PM
DataAdapter using commandbuilder's commands, not it's own. Marina Microsoft ASP .NET 1 12th Dec 2003 05:46 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:08 PM.