473,406 Members | 2,387 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,406 software developers and data experts.

Inspecting the ADO

M D

cmd.CommandText = "SELECT TOP 1 * FROM " + target.Text;
conn.Open();
tableReader = cmd.ExecuteReader();
schemaTable = tableReader.GetSchemaTable();

where k is the primary key field:

schemaTable.Rows[k]["IsKey"]

does not show as true while

schemaTable.Rows[k]["AllowDBNull"]

does show as not nullable (and all the other schema values I've used are
also correct)

anyone know why?

the database is SQL2000
thx
md

*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #1
8 2315
M D wrote:
cmd.CommandText = "SELECT TOP 1 * FROM " + target.Text;
conn.Open();
tableReader = cmd.ExecuteReader();
schemaTable = tableReader.GetSchemaTable();

where k is the primary key field:

schemaTable.Rows[k]["IsKey"]

does not show as true while

schemaTable.Rows[k]["AllowDBNull"]

does show as not nullable (and all the other schema values I've used
are also correct)

anyone know why?


I had similar problems when playing around with ADO.NET and Microsoft
Access. As far as I remember Unique didn't work either if it wasn't set for
primary key columns.
My solution was to use DataTable.PrimaryKey and
OleDbConnection.GetOleDbSchemaTable() but I think the latter is OLE DB
specific and might not be available for SQL Server.

Boris
Nov 16 '05 #2
M D wrote:
cmd.CommandText = "SELECT TOP 1 * FROM " + target.Text;
conn.Open();
tableReader = cmd.ExecuteReader();
schemaTable = tableReader.GetSchemaTable();

where k is the primary key field:

schemaTable.Rows[k]["IsKey"]

does not show as true while

schemaTable.Rows[k]["AllowDBNull"]

does show as not nullable (and all the other schema values I've used
are also correct)

anyone know why?


I had similar problems when playing around with ADO.NET and Microsoft
Access. As far as I remember Unique didn't work either if it wasn't set for
primary key columns.
My solution was to use DataTable.PrimaryKey and
OleDbConnection.GetOleDbSchemaTable() but I think the latter is OLE DB
specific and might not be available for SQL Server.

Boris
Nov 16 '05 #3
M D
I think the only difference between
OleDbConnection.GetOleDbSchemaTable() and
OleDbDataReader.GetSchemaTable() is that the data reader already knows
what table it is scheming while the connection needs to be given a guid
of the table in question.

However, are you sure your solution worked?

The Get operations deliver a DataTable representing the schema of
another "DataTable" (eg name in target.Text.)

schemaTable.PrimaryKey yields the pkey of the schema not the target.
One must read the schemaTable DATA to locate information about the
target.

Do you mean that you turned the target table into a DataTable and got
its pkey? If that table had any size wasn't it expensive to load?

thx
md

*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #4
M D wrote:
[...]
schemaTable.PrimaryKey yields the pkey of the schema not the target.
One must read the schemaTable DATA to locate information about the
target.
Ah, okay: I used OleDbDataAdapter.FillSchema() which initializes
DataTable.PrimaryKey.
Do you mean that you turned the target table into a DataTable and got
its pkey? If that table had any size wasn't it expensive to load?


I don't know how expensive it is to use FillSchema(). But as I couldn't find
any other way to get the primary key calling FillSchema() was the best I
could do?

Boris
Nov 16 '05 #5
M D
Yes, that is what I've got on the list to try next.

And, you've inspired me to the sql... group from the OleDb... group. I
want to see if the "IsKey" works if I go native.

thx
md

*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #6
M D
Here is the solution:

cmd.ExecuteReader(CommandBehavior.KeyInfo);

The Samaritan that shared this with me says the behavior is not included
in the default due to a performance hit.
thx
md

*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #7
M D
Here is the solution:

cmd.ExecuteReader(CommandBehavior.KeyInfo);

The Samaritan that shared this with me says the behavior is not included
in the default due to a performance hit.
thx
md

*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #8
M D wrote:
Here is the solution:

cmd.ExecuteReader(CommandBehavior.KeyInfo);

The Samaritan that shared this with me says the behavior is not
included in the default due to a performance hit.


Ah, learnt something new. Thanks for sharing this information again. :)

Boris
Nov 16 '05 #9

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

Similar topics

4
by: Ruby Tuesday | last post by:
Is there a fast way to read files/directory recursively? Instead of inspecting each file(s)/dir(s), is there a way to know that its a file or a directory from its hidden attribut both for windows...
2
by: herc777 | last post by:
Is it possible for javascript to inspect the contents of an iframe or is it an external object? <iframe id="myiframe" src=""> <script> document.getElementById.myiframe.src =...
2
by: Zlatko Matić | last post by:
Hi. How to check whether some form is open or not, in VBA ? Thanks.
8
by: kelin,zzf818 | last post by:
Hi, Today I read the following sentences, but I can not understand what does the __init__ method of a class do? __init__ is called immediately after an instance of the class is created. It...
4
by: Philippe Roy | last post by:
We finished creating a speech recognition program (http:// www.speechvibe.com), and want to enhance its capabilities to web browsers. I need, from outside (so without having access nor changing...
76
by: dbansal | last post by:
Hi group, I have a question to ask you all. I have allocated some chunk of memory using ptr=(int*)malloc(). now I am trying to free that memory using free((void*)ptr). My question is does free()...
4
by: David Jackson | last post by:
Hello, I've been asked to write a sort of "desktop clean-up" utility. Requirements are simple: iterate through the shortcuts (*.lnk files) on the currently logged-on user's desktop, and delete...
1
by: BrendanC | last post by:
I'm trying to understand reflection/introspection in Python. How can I identify the the type of attribute (e.g. instance var) in a class? The following returns all the class attributes (methods and...
2
by: =?Utf-8?B?cm9kY2hhcg==?= | last post by:
hey all, you know how in the immediate window you can inspect an objects property, i was just wondering if there was a way to display all that on my web page in a div or something? thanks,...
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
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
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
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
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,...

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.