473,396 Members | 1,757 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Database datatype to c# datatype

Hi

I am reading metadata from a database (sql server) - for example metadata
describing columns in a table. This metadata includes information about the
datatype of the column - for example "decimal", "small int", "varchar",
"image", "char" and so on.

Is there some built-in functionality in .net for converting these datatypes
to c# datatypes? For example, "varchar" could map to System.string. Or do I
need to write my own type-mapping method?
Thanks,
Peter
May 31 '06 #1
3 2783
For most DAL purposes you know the type (per column) in advance, since you
designed the database; for more generic usage, you can always use
GetFieldType() and GetValue() on any IDataReader.

Would that do?

Marc
May 31 '06 #2

"Marc Gravell" <ma**********@gmail.com> skrev i en meddelelse
news:ur**************@TK2MSFTNGP04.phx.gbl...
For most DAL purposes you know the type (per column) in advance, since you
designed the database; for more generic usage, you can always use
GetFieldType() and GetValue() on any IDataReader.

Would that do?


Not quite (I don't think), because I get metadata about a database column:

name
default value
is nullable
data type

ie, I get an IDataReader which contains some "string columns", which provide
information about a column in a database table.

One of the items of data describing the column is a string value which gives
the data type of the column. For example, this string value could be
"varchar" or "int".

I want to convert this string value to a c# datatype.

Peter
May 31 '06 #3
Peter Kirk wrote:
Hi

I am reading metadata from a database (sql server) - for example
metadata describing columns in a table. This metadata includes
information about the datatype of the column - for example "decimal",
"small int", "varchar", "image", "char" and so on.

Is there some built-in functionality in .net for converting these
datatypes to c# datatypes? For example, "varchar" could map to
System.string. Or do I need to write my own type-mapping method?


There is no such method.

FB

--
------------------------------------------------------------------------
Lead developer of LLBLGen Pro, the productive O/R mapper for .NET
LLBLGen Pro website: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------
Jun 1 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Greg Horwood | last post by:
Dear All, Can anyone suggest why the following code returns an error: DataRow drNewRow = m_table.NewRow(); drNewRow = "222"; m_table.Rows.Add(drNewRow); m_daDataAdapter.Update(m_table); ...
3
by: den 2005 | last post by:
Hi everyone, Here is code working on..Trying to insert record with a column with Image or VarBinary datatype in sql database from a existing jpeg image file, then retrieve this image from...
10
by: C# Beginner | last post by:
Hi there, I'm currently trying to create a MS access file at runtime, but I stumble into some problems. 1. When I use Datatype adUnsignedInt I get an error (invalid type). 2. Which datatype...
3
by: =?Utf-8?B?ZGF2aWQ=?= | last post by:
I try to follow Steve's paper to build a database, and store a small text file into SQL Server database and retrieve it later. Only difference between my table and Steve's table is that I use NTEXT...
0
by: rejithes | last post by:
Hi, I had an application in which database swing will happen automatically. Some of my tables have field datatype - TEXT. It is found that the TEXT datatype is getting corrupted after database...
4
by: vunet.us | last post by:
I want to know if this practice is effective and secure: I have been thinking about storing some data, which my users upload, in text files rather than database, since often I do not know how much...
0
by: jenniamia | last post by:
I'm new to programming, so this might be simpler than I realize but I'd appreciate a push in the right direction. I'm using VS.NET 2005 with a database, SQL 2000. I'm writing in C# code and I'm...
0
by: mchirouze | last post by:
Hi, I have been working on this piece of code which lists all tables in a MS Access database (including linked tables) and converts them to a DataTable with a pre-defined format. I use ADOX and...
12
by: Andy B | last post by:
I need to custom build and use a dataset in c# to use with xml. Does anybody know where I can find out how to do something like this? I was going to create a class that generated the dataset and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.