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

Home Posts Topics Members FAQ

SQL Server table Schema

JPS
Does anyone know how to query a table and get the schema
informationback as well as the values in the fields. Here is what I
have done so far. I cannot get both.

using (SqlConnection conF = new
SqlConnection ( "server=" + srvr +
";Integrated Security=SSPI;database=" + dbName +
";Initial Catalog=" + tblNames[tbl].ToString
( )))
{
conF.Open ( );
SqlCommand sqlCmd = new SqlCommand ( );

sqlCmd = conF.CreateCommand ( );

sqlCmd.CommandText = "SELECT * FROM
INFORMATION_SCHEMA.COLUMNS";
SqlDataReader sqlDr = sqlCmd.ExecuteReader ( );
int fc = 0;
if (sqlDr.FieldCount 0)
{
while (sqlDr.Read ( ))
{
fc++;
for (int h = 0; h <= sqlDr.FieldCount - 1;
h++)
{
Debug.WriteLine ( sqlDr[h].ToString ( )
);
}

//foreach (DataRow dr in dt.Rows)
//{
// //Debug.WriteLine ( dr[x] );
// foreach (DataColumn dc in dt.Columns)
// {
// Debug.WriteLine ( dc.ColumnName +
" Value: " + sqlDr[x].ToString() );
// x++;
// }
//}
}
}
conF.Close ( );

Jan 10 '07 #1
3 1802
>Does anyone know how to query a table and get the schema
>informationback as well as the values in the fields. Here is what I
have done so far. I cannot get both.
That's correct - you cannot get both at the same time - they're very
different things indeed.

Schema information for a table (info about the columns) is a once per
table thing and it's the same for all row - that's what we have come
to except, right? This information is stored in the database's data
dictionary (or whatever it might be called today).

Data is a per-row thing - a table can have many rows - and that data
is stored in the table itself - that's the whole point of it.

So I don't see how you could get both types of information in the same
call - it's just not possible. Why would you even need this??

Marc
Jan 11 '07 #2
So I don't see how you could get both types of information in the same
call - it's just not possible. Why would you even need this??
I think DataReaders have a method called GetSchemaTable() that returns
the table schema while you read the data. You could use this to figure
out how to deal with the data records, if you don't know what types to
expect.

Jan 11 '07 #3
Tom Chen wrote:
I tried Information_schema.Columns. CHARACTER_MAXIMUM_LENGTH and
CHARACTER_OCTET_LENGTH only work for char and varchar.

How can I get text, image and integer type length?
They are meaningless/fixed for those data types.
Does default asp.net account in SQL Server has default right to visit
Information_Schema and sp_help?
Look it up.

Arne
Jan 23 '07 #4

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

Similar topics

5
by: dananrg | last post by:
I've created a small company database where the tables reside in a SQL Server database. I'm using Access 2000 forms for a front end. I've got a System DSN set-up to SQL Server and am using links...
2
by: Amanda | last post by:
From a guy in Microsoft newsgroups: | In *comp.databases.ibm-db2* there are always IBM guys | from the Toronto labs on line.Post with the | -for the love of god please help- | line...
7
by: slitvinov | last post by:
I am learning Relax NG. The problem is that I cannot figure out how to make a schema for a table. In my case I would like to make a table with any name of child elements (columns) but columns...
2
by: Jobs | last post by:
Download the JAVA , .NET and SQL Server interview with answers Download the JAVA , .NET and SQL Server interview sheet and rate yourself. This will help you judge yourself are you really worth of...
6
by: Amber | last post by:
do the following steps: 1:Use Manage Studio login the server with Integrated security. 2:Create a dabase named testdb; 3:Create a SQL Server login named amber ,and set it to be dbowner of...
1
by: System Audit | last post by:
I am working with an old version of SQL Server (6.5), but the same mechanism may exist in later versions. If there were any changes made to the database schema, would this be recorded somewhere...
4
by: =?Utf-8?B?Sm9iIExvdA==?= | last post by:
how can persist schema for a sql server table into an xml file from .net application? thanks
4
by: dkirkdrei | last post by:
I am having a problem getting results back from a SELECT statement using the script below. The field names contain decimals and I am not sure wether or not this is causing the problem or not?? I am...
8
by: send.me.all.email | last post by:
Hi experts, which approaches would you suggest for: - Reading a database schema (tables, fields, relationships) from SQL Server 2005? - Visualizing the DB schema? For developing a DB tool...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
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...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.