473,473 Members | 1,477 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Reading *exact* SQL types from database

Hello,

I've managed to read an sql type from the database (using a kind of virtual
commandbuilder and SqlDbType method) but I'm not able to retrieve exact data
type (eg. maximum length of a varchar field), ie. I can only retrieve
"NVarChar" type while the true type name is "NVarChar(50)". I hope you know
what I mean, and I really hope somebody here could help me with this.

Regards,
Mike
Jun 27 '06 #1
6 2215
Hi,

You would have to read this info from one of the system tables syscolums
IIRC.
--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Baal80" <Ba****@discussions.microsoft.com> wrote in message
news:72**********************************@microsof t.com...
Hello,

I've managed to read an sql type from the database (using a kind of
virtual
commandbuilder and SqlDbType method) but I'm not able to retrieve exact
data
type (eg. maximum length of a varchar field), ie. I can only retrieve
"NVarChar" type while the true type name is "NVarChar(50)". I hope you
know
what I mean, and I really hope somebody here could help me with this.

Regards,
Mike

Jun 27 '06 #2
If you want to do what I think you want to do, you can execute the GetSchema
call on the connection and then go through the 'Columns' collection
Baal80 wrote:
Hello,

I've managed to read an sql type from the database (using a kind of virtual
commandbuilder and SqlDbType method) but I'm not able to retrieve exact data
type (eg. maximum length of a varchar field), ie. I can only retrieve
"NVarChar" type while the true type name is "NVarChar(50)". I hope you know
what I mean, and I really hope somebody here could help me with this.

Regards,
Mike

Jun 27 '06 #3
Hi,
"Ian Semmel" <is***********@NOKUNKrocketcomp.com.au> wrote in message
news:Om**************@TK2MSFTNGP05.phx.gbl...
If you want to do what I think you want to do, you can execute the
GetSchema call on the connection and then go through the 'Columns'
collection


Not sure if this will return the correct type name in the DB. Most probably
you will get the .NET equivalent.

But I'm not sure about this.

--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
Jun 28 '06 #4
Not sure if this helps, but I get the schema of a table as follows. One of
the coumns returned is the "provider" data type, rather than the .Net data
type.

// To get the schema, we need to execute a select command.
cmd.Connection = dBase;
cmd.CommandText = "SELECT * FROM [" + strTableName + "];";

try
{
// Create the datareader, retrieving only the schema information
dataReader = cmd.ExecuteReader(CommandBehavior.KeyInfo);
// Copy the stuff we retrieved in to a data table
schemaTable = dataReader.GetSchemaTable();
// And give the data table a name that we can work with.
schemaTable.TableName = "ColumnNames";
// We don't need the data reader any more - we have what we want
dataReader.Close();

dsTemp.Tables.Add(schemaTable);

...

foreach(DataRow drColumn in dsTemp.Tables["ColumnNames"].Rows)
{
... do stuff

// There is a column with the "provider" data type in it...
columnDef.DataType =
((OleDbType)drColumn["ProviderType"]).ToString();

...
}
HTH
Steve.
"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us> wrote
in message news:%2******************@TK2MSFTNGP03.phx.gbl...
Hi,
"Ian Semmel" <is***********@NOKUNKrocketcomp.com.au> wrote in message
news:Om**************@TK2MSFTNGP05.phx.gbl...
If you want to do what I think you want to do, you can execute the
GetSchema call on the connection and then go through the 'Columns'
collection


Not sure if this will return the correct type name in the DB. Most
probably you will get the .NET equivalent.

But I'm not sure about this.

--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

Jun 28 '06 #5
In the 'Columns' collection, you get for example, this

TABLE_CATALOG = C:\PROGRAM FILES\MICROSOFT SQL SERVER\MSSQL.1\MSSQL\DATA\QFRS.MDF
TABLE_SCHEMA = dbo
TABLE_NAME = Activity
COLUMN_NAME = ActivityDate
ORDINAL_POSITION = 2
COLUMN_DEFAULT =
IS_NULLABLE = NO
DATA_TYPE = datetime (*** SQL Type ***)
CHARACTER_MAXIMUM_LENGTH =
CHARACTER_OCTET_LENGTH =
NUMERIC_PRECISION =
NUMERIC_PRECISION_RADIX =
NUMERIC_SCALE =
DATETIME_PRECISION = 3
CHARACTER_SET_CATALOG =
CHARACTER_SET_SCHEMA =
CHARACTER_SET_NAME =
COLLATION_CATALOG =

In the 'DataType' collection you get

TypeName = datetime
ProviderDbType = 4
ColumnSize = 23
CreateFormat = datetime
CreateParameters =
DataType = System.DateTime (*** C# Type ***)
IsAutoIncrementable = False
IsBestMatch = True
IsCaseSensitive = False
IsFixedLength = True
IsFixedPrecisionScale = False
IsLong = False
IsNullable = True
IsSearchable = True
IsSearchableWithLike = True
IsUnsigned =
MaximumScale =
MinimumScale =
IsConcurrencyType = False
IsLiteralSupported =
LiteralPrefix = {ts '
LiteralSuffix = '}
Ignacio Machin ( .NET/ C# MVP ) wrote:
Hi,
"Ian Semmel" <is***********@NOKUNKrocketcomp.com.au> wrote in message
news:Om**************@TK2MSFTNGP05.phx.gbl...
If you want to do what I think you want to do, you can execute the
GetSchema call on the connection and then go through the 'Columns'
collection

Not sure if this will return the correct type name in the DB. Most probably
you will get the .NET equivalent.

But I'm not sure about this.

Jun 28 '06 #6
Hi,
Good to know, I did not know you had this info returned in the Columns
collection

--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Ian Semmel" <is***********@NOKUNKrocketcomp.com.au> wrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
In the 'Columns' collection, you get for example, this

TABLE_CATALOG = C:\PROGRAM FILES\MICROSOFT SQL
SERVER\MSSQL.1\MSSQL\DATA\QFRS.MDF
TABLE_SCHEMA = dbo
TABLE_NAME = Activity
COLUMN_NAME = ActivityDate
ORDINAL_POSITION = 2
COLUMN_DEFAULT =
IS_NULLABLE = NO
DATA_TYPE = datetime (*** SQL Type ***)
CHARACTER_MAXIMUM_LENGTH =
CHARACTER_OCTET_LENGTH =
NUMERIC_PRECISION =
NUMERIC_PRECISION_RADIX =
NUMERIC_SCALE =
DATETIME_PRECISION = 3
CHARACTER_SET_CATALOG =
CHARACTER_SET_SCHEMA =
CHARACTER_SET_NAME =
COLLATION_CATALOG =

In the 'DataType' collection you get

TypeName = datetime
ProviderDbType = 4
ColumnSize = 23
CreateFormat = datetime
CreateParameters =
DataType = System.DateTime (*** C# Type ***)
IsAutoIncrementable = False
IsBestMatch = True
IsCaseSensitive = False
IsFixedLength = True
IsFixedPrecisionScale = False
IsLong = False
IsNullable = True
IsSearchable = True
IsSearchableWithLike = True
IsUnsigned =
MaximumScale =
MinimumScale =
IsConcurrencyType = False
IsLiteralSupported =
LiteralPrefix = {ts '
LiteralSuffix = '}
Ignacio Machin ( .NET/ C# MVP ) wrote:
Hi,
"Ian Semmel" <is***********@NOKUNKrocketcomp.com.au> wrote in message
news:Om**************@TK2MSFTNGP05.phx.gbl...
If you want to do what I think you want to do, you can execute the
GetSchema call on the connection and then go through the 'Columns'
collection

Not sure if this will return the correct type name in the DB. Most
probably you will get the .NET equivalent.

But I'm not sure about this.


Jun 28 '06 #7

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

Similar topics

3
by: Johan Vervoort | last post by:
How can I read a binary value from a blob via ODBC (Microsoft VFP driver-win32all)? The value seems to be truncated at the first '\0' TIA
3
by: Catherine Lynn Smith | last post by:
I'm looking through the client side javascript reference and there's some mighty useful information in here, but it is not very specific on 'reading' information from event handlers. In the...
3
by: Harry Overs | last post by:
I'm using the ifstream to read the contents of a file using the >> operators. However the problem that I have is that the file is made up of double and string variables. Is there an easy way to...
14
by: Zahid | last post by:
Hi, What is a VDT file? How do I read a VDT file into my application? I know how to read text files etc but not VDT files. Im preparing in advance a prototype that read VDT files and does...
4
by: Jason Kumpf | last post by:
OK I've been staring at this code all day and still with everything I have tried I cannot figure out two problems I am having. Once is why the space limit for the directory I create in the code...
6
by: arne.muller | last post by:
Hello, I've come across some problems reading strucutres from binary files. Basically I've some strutures typedef struct { int i; double x; int n; double *mz;
12
by: SAL | last post by:
Hello, Is it possible to read a CSV from the Client, and bind my Datagrid to the data in the CSV file without uploading the file to the Server first? I have tried and in Debug mode on my...
29
by: Jerim79 | last post by:
I did try to find the answer to this before posting, so this isn't a knee jerk reaction. What I am trying to accomplish is to have a script that opens a cookie, reads a value, and then use a...
2
by: dhanashivam | last post by:
hi all, i am creating a VB6.0 application with Ms-Access database. While reading a memo field of my Ms-Access database, the recordset shows some invalid bad charecters like "(1of 2) Deemed...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...
1
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.