Getting a .NET type given a database-specific type name

J

jehugaleahsa

Hello:

Say I were to query the schema tables from a database management
system. Say I got a DataType field that held the string 'VARCHAR2'.
Now, I know that VARCHAR2 associates to System.String. However,
different DBMSs have different types and worse, even some with the
same type turn out to be different .NET types.

I would like DMBS-independent way of getting a .NET type from a
DataType string. Now, I have existing code that gets the .NET type by
using a DataTable. Somehow DataTables have the .NET types. How is this
done? Do the providers implement the conversion themselves?

Any insight or solutions would be greatly appreciated!

Thanks,
Travis
 
E

Edwin van Holland

Travis,

Although some types might have been registered in the .NET framework
(Perhaps MSSQL types, not sure!) I don't think all providerd will write
conversion packs. The .NET framework will probably do multiple casts and
returns the most likely result type to your datatable.

Edwin
 
J

jehugaleahsa

Travis,

Although some types might have been registered in the .NET framework
(Perhaps MSSQL types, not sure!) I don't think all providerd will write
conversion packs. The .NET framework will probably do multiple casts and
returns the most likely result type to your datatable.

Edwin









- Show quoted text -

My biggest problem is that I am not given a column in a table, so that
I could query it. For instance, I am some times given a stored
procedure definition and want to know what the parameter types are.

I can query the metadata table, but it will always return a string
that represents that type on the DBMS. I don't want to have a switch
statement with all the types on the database to map to a .NET type.
Even more, I think calling FillSchema or something similar is overkill
for something that may be called many, many times.

My overall goal to provide the developers here code that would
generate the C# code that would execute a stored procedure. I have
written code that will access the meta data tables and figure out
information about the stored procedures. Right now, my library
supports MySQL, Oracle, MSSQL, PostgreSQL and Access.

With a large number of supported databases and the potential for more,
manually entering in type conversion is buggy and tedious.

I was hoping there was a tool available or a trick to getting the
information.

Thanks for your reply.
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

As you mentioned the mapping change depending of the RDBMS you use. So there
is no way of doing it.
 
J

jehugaleahsa

Hi,

As you mentioned the mapping change depending of the RDBMS you use. So there
is no way of doing it.

Somewhere at some point, someone wrote code to get the .NET type from
the database. There are two possibilities: each RDBMS is responsible
for specifying the mapping; Microsoft somehow wrote a generic class
that could extract the type given an instance of the result. But,
again, I don't have a result.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top