Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / January 2008

Tip: Looking for answers? Try searching our database.

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

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
jehugaleahsa@gmail.com - 17 Jan 2008 21:07 GMT
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
Edwin van Holland - 17 Jan 2008 21:42 GMT
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

> Hello:
>
[quoted text clipped - 13 lines]
> Thanks,
> Travis
jehugaleahsa@gmail.com - 17 Jan 2008 22:13 GMT
On Jan 17, 2:42 pm, Edwin van Holland <edwinvanholl...@hotmail.com>
wrote:
> Travis,
>
[quoted text clipped - 25 lines]
>
> - 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.
Ignacio Machin ( .NET/ C# MVP ) - 18 Jan 2008 14:38 GMT
Hi,

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

Signature

Ignacio Machin
http://www.laceupsolutions.com
Mobile & warehouse Solutions.

> Hello:
>
[quoted text clipped - 13 lines]
> Thanks,
> Travis
jehugaleahsa@gmail.com - 19 Jan 2008 04:41 GMT
On Jan 18, 7:38 am, "Ignacio Machin \( .NET/ C# MVP \)" <machin TA
laceupsolutions.com> wrote:
> Hi,
>
[quoted text clipped - 24 lines]
> > Thanks,
> > Travis

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.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.