PC Review


Reply
Thread Tools Rate Thread

Extended Properties Not Showing Up

 
 
localhost
Guest
Posts: n/a
 
      13th Sep 2004


I have created a table in MSSQL2K and added an Extended Property to
it.
I want the Extended Property to show up in the result DataSet. What
should I change to make this happen?

TSQL:


Create Table dbo.ZTestTable (
"ZTestTable_Id" int not null, "Col-1" varchar(184) null,
"Col-2" varchar(238) null
)
Go

Exec sp_addextendedproperty
'TableType', 'A test table.', 'user', dbo, 'table', [ZTestTable]
Go

Exec sp_addextendedproperty
'ColumnComment', 'ZTestTable primary key identifier.', 'user', dbo,
'table', [ZTestTable], 'column', [ZTestTable_Id]
Go

grant select on ZTestTable to public

Go



C#:

using System;
using System.Data;
using System.Data.OleDb;


class ExtenTest
{
[STAThread]
static void Main(string[] args)
{
DataSet outSet = new DataSet( "OutSet" );
string connString = "DATABASE=.........."

// string selectIt = "Select * From ::fn_listextendedproperty " +
"('TableType', 'user', 'dbo', 'table','ZTestTable',
null, null)";
string selectIt = "select * from ZTestTable";

OleDbConnection dbCn = new OleDbConnection( connString );
dbCn.Open();

OleDbDataAdapter dbAda = new OleDbDataAdapter( selectIt , dbCn
);
dbAda.Fill( outSet );
outSet.WriteXml( @"c:\extentest.xml" ,
XmlWriteMode.WriteSchema );

}
}



Thanks.

 
Reply With Quote
 
 
 
 
Kevin Yu [MSFT]
Guest
Posts: n/a
 
      14th Sep 2004
Hi localhost,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you need to get extended properties of
a table and fill them to a DataSet. If there is any misunderstanding,
please feel free to let me know.

I have tried your code on my computer, However, I didn't see any exceptions
during running. The properties have been filled and written to the output
xml file. Could you let me know where the problem is?

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

 
Reply With Quote
 
localhost
Guest
Posts: n/a
 
      14th Sep 2004


I looked at the serialized DataSet and do not see the extended
properties in the schema.

This is the output I get when I view extentest.xml:

<?xml version="1.0" standalone="yes" ?>
<OutSet>
<xs:schema id="OutSet" xmlns=""
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="OutSet" msdata:IsDataSet="true">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element name="Table">
<xs:complexType>
<xs:sequence>
<xs:element name="ZTestTable_Id" type="xs:int" minOccurs="0" />
<xs:element name="Col-1" type="xs:string" minOccurs="0" />
<xs:element name="Col-2" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
</OutSet>

I see the table name and column names.
I do not see anything that says "ColumnComment" or "ZTestTable primary
key identifier.".
I want to pull back a result set from SQL Server and any Extended
properties for the
table and columns. I know they are in the DB. How do I get them into
my DataSet?

Thanks.


-----------------------

On Tue, 14 Sep 2004 07:11:29 GMT, v-(E-Mail Removed) (Kevin
Yu [MSFT]) wrote:

>Hi localhost,
>
>First of all, I would like to confirm my understanding of your issue. From
>your description, I understand that you need to get extended properties of
>a table and fill them to a DataSet. If there is any misunderstanding,
>please feel free to let me know.
>
>I have tried your code on my computer, However, I didn't see any exceptions
>during running. The properties have been filled and written to the output
>xml file. Could you let me know where the problem is?
>
>Kevin Yu
>=======
>"This posting is provided "AS IS" with no warranties, and confers no
>rights."


 
Reply With Quote
 
Kevin Yu [MSFT]
Guest
Posts: n/a
 
      15th Sep 2004
Hi localhost,

I have been following your steps, however, I didn't reproduce it.
XmlWriteMode.WriteSchema will write schema together with data into xml.
Please try to put a DataGrid on the form to display the DataSet. And use
Select * From ::fn_listextendedproperty ('TableType', 'user', 'dbo',
'table','ZTestTable',null, null) in Query Analyzer to check if the extend
properties have been added to the table. Please also make sure that you
have connected to the correct database.

The following is the xml file I have get with WriteXml.

<?xml version="1.0" standalone="yes"?>
<OutSet>
<xs:schema id="OutSet" xmlns=""
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="OutSet" msdata:IsDataSet="true">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element name="Table">
<xs:complexType>
<xs:sequence>
<xs:element name="objtype" type="xs:string" minOccurs="0" />
<xs:element name="objname" type="xs:string" minOccurs="0" />
<xs:element name="name" type="xs:string" minOccurs="0" />
<xs:element name="value" msdataataType="System.Object,
mscorlib, Version=1.0.5000.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
<Table>
<objtype>TABLE</objtype>
<objname>ZTestTable</objname>
<name>TableType</name>
<value>A test table.</value>
</Table>
</OutSet>

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

 
Reply With Quote
 
localhost
Guest
Posts: n/a
 
      15th Sep 2004

I used Query Analyzer and see that the Extended Properties show up for
both the table and the column ZTestTable_Id.

I do not understand how code that I run on my machine creates
completely different results on your machine. I am running .NET
Framework 1.1-SP1 on WinXP-SP1.

Please post the code that you ran, and please explain why the
ColumnComment Extended Attribute is not showing in your XMLized
DataSet.

Thanks.



On Wed, 15 Sep 2004 08:45:54 GMT, v-(E-Mail Removed) (Kevin
Yu [MSFT]) wrote:

>Hi localhost,
>
>I have been following your steps, however, I didn't reproduce it.
>XmlWriteMode.WriteSchema will write schema together with data into xml.
>Please try to put a DataGrid on the form to display the DataSet. And use
>Select * From ::fn_listextendedproperty ('TableType', 'user', 'dbo',
>'table','ZTestTable',null, null) in Query Analyzer to check if the extend
>properties have been added to the table. Please also make sure that you
>have connected to the correct database.
>
>The following is the xml file I have get with WriteXml.
>
><?xml version="1.0" standalone="yes"?>
><OutSet>
> <xs:schema id="OutSet" xmlns=""
>xmlns:xs="http://www.w3.org/2001/XMLSchema"
>xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
> <xs:element name="OutSet" msdata:IsDataSet="true">
> <xs:complexType>
> <xs:choice maxOccurs="unbounded">
> <xs:element name="Table">
> <xs:complexType>
> <xs:sequence>
> <xs:element name="objtype" type="xs:string" minOccurs="0" />
> <xs:element name="objname" type="xs:string" minOccurs="0" />
> <xs:element name="name" type="xs:string" minOccurs="0" />
> <xs:element name="value" msdataataType="System.Object,
>mscorlib, Version=1.0.5000.0, Culture=neutral,
>PublicKeyToken=b77a5c561934e089" type="xs:string" minOccurs="0" />
> </xs:sequence>
> </xs:complexType>
> </xs:element>
> </xs:choice>
> </xs:complexType>
> </xs:element>
> </xs:schema>
> <Table>
> <objtype>TABLE</objtype>
> <objname>ZTestTable</objname>
> <name>TableType</name>
> <value>A test table.</value>
> </Table>
></OutSet>
>
>Kevin Yu
>=======
>"This posting is provided "AS IS" with no warranties, and confers no
>rights."


 
Reply With Quote
 
Kevin Yu [MSFT]
Guest
Posts: n/a
 
      16th Sep 2004
Hi localhost,

The following is the code I am using.

DataSet outSet = new DataSet( "OutSet" );
string selectIt = "Select * From ::fn_listextendedproperty " +
"('TableType', 'user', 'dbo', 'table','ZTestTable',null, null)";

OleDbDataAdapter dbAda = new OleDbDataAdapter( selectIt ,
this.oleDbConnection1);
dbAda.Fill( outSet );
outSet.WriteXml( @"c:\extentest.xml", XmlWriteMode.WriteSchema );
this.dataGrid1.DataSource = outSet;

Both DataGrid and xml file shows the extended property values. You can see
it in the <table> tag of xml.

<Table>
<objtype>TABLE</objtype>
<objname>ZTestTable</objname>
<name>TableType</name>
<value>A test table.</value>
</Table>

I think you might not connecting to the correct database.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

 
Reply With Quote
 
localhost
Guest
Posts: n/a
 
      16th Sep 2004

I am connecting to the correct database.

You did not execute the code I posted, you altered it.


Line 14 of my C# code was commented out. I left it there
as a test to verify that the Extended Properties exist in
SQL Server, and to show you that I already know how to do
that.

Line 17 is not commented because that is the kind of
query I expect to run. I just want to query the DB,
and if any extended properties exist on the table
or column, I want them returned along with the result set.


I think you do not understand what I am asking. Is it
possible for you to get input from another MS engineer
or MVP?


Thanks.





_______ original message _______



I have created a table in MSSQL2K and added an Extended Property to
it.
I want the Extended Property to show up in the result DataSet. What
should I change to make this happen?

TSQL:


Create Table dbo.ZTestTable (
"ZTestTable_Id" int not null, "Col-1" varchar(184) null,
"Col-2" varchar(238) null
)
Go

Exec sp_addextendedproperty
'TableType', 'A test table.', 'user', dbo, 'table', [ZTestTable]
Go

Exec sp_addextendedproperty
'ColumnComment', 'ZTestTable primary key identifier.', 'user', dbo,
'table', [ZTestTable], 'column', [ZTestTable_Id]
Go

grant select on ZTestTable to public

Go



C#:

using System;
using System.Data;
using System.Data.OleDb;


class ExtenTest
{
[STAThread]
static void Main(string[] args)
{
DataSet outSet = new DataSet( "OutSet" );
string connString = "DATABASE=.........."

// string selectIt = "Select * From ::fn_listextendedproperty " +
"('TableType', 'user', 'dbo', 'table','ZTestTable',
null, null)";
string selectIt = "select * from ZTestTable";

OleDbConnection dbCn = new OleDbConnection( connString );
dbCn.Open();

OleDbDataAdapter dbAda = new OleDbDataAdapter( selectIt , dbCn
);
dbAda.Fill( outSet );
outSet.WriteXml( @"c:\extentest.xml" ,
XmlWriteMode.WriteSchema );

}
}



Thanks.

 
Reply With Quote
 
Patrice
Guest
Posts: n/a
 
      16th Sep 2004
Not an MS engineer or MVP but I'll give it a try.

It looks like you expect to have extended properties returned just by using
a SELECT * FROM MaTable statement with the usual resultset. It just not the
way it works.

Remember that extended properties are tied to COLUMNS not ROWS. As such you
won't find an additional column with the extended properties values (and
that would have anyway the same value for all rows) as you seem to expect.
You'll have to query extended properties separately. The result set will
contains a row for each column and property.

You may want to describe what you want to do with extended properties.

IMO you'll have to do it as a two step process in your data layer :
- have the data layer returning extended properties for each COLUMN (using
fn_listextendedporperties)
- then return ROWS (using SELECT * FROM MaTable)

Hope it helps.

--

"localhost" <(E-Mail Removed)> a écrit dans le message de
news:(E-Mail Removed)...
>
> I am connecting to the correct database.
>
> You did not execute the code I posted, you altered it.
>
>
> Line 14 of my C# code was commented out. I left it there
> as a test to verify that the Extended Properties exist in
> SQL Server, and to show you that I already know how to do
> that.
>
> Line 17 is not commented because that is the kind of
> query I expect to run. I just want to query the DB,
> and if any extended properties exist on the table
> or column, I want them returned along with the result set.
>
>
> I think you do not understand what I am asking. Is it
> possible for you to get input from another MS engineer
> or MVP?
>
>
> Thanks.
>
>
>
>
>
> _______ original message _______
>
>
>
> I have created a table in MSSQL2K and added an Extended Property to
> it.
> I want the Extended Property to show up in the result DataSet. What
> should I change to make this happen?
>
> TSQL:
>
>
> Create Table dbo.ZTestTable (
> "ZTestTable_Id" int not null, "Col-1" varchar(184) null,
> "Col-2" varchar(238) null
> )
> Go
>
> Exec sp_addextendedproperty
> 'TableType', 'A test table.', 'user', dbo, 'table', [ZTestTable]
> Go
>
> Exec sp_addextendedproperty
> 'ColumnComment', 'ZTestTable primary key identifier.', 'user', dbo,
> 'table', [ZTestTable], 'column', [ZTestTable_Id]
> Go
>
> grant select on ZTestTable to public
>
> Go
>
>
>
> C#:
>
> using System;
> using System.Data;
> using System.Data.OleDb;
>
>
> class ExtenTest
> {
> [STAThread]
> static void Main(string[] args)
> {
> DataSet outSet = new DataSet( "OutSet" );
> string connString = "DATABASE=.........."
>
> // string selectIt = "Select * From ::fn_listextendedproperty " +
> "('TableType', 'user', 'dbo', 'table','ZTestTable',
> null, null)";
> string selectIt = "select * from ZTestTable";
>
> OleDbConnection dbCn = new OleDbConnection( connString );
> dbCn.Open();
>
> OleDbDataAdapter dbAda = new OleDbDataAdapter( selectIt , dbCn
> );
> dbAda.Fill( outSet );
> outSet.WriteXml( @"c:\extentest.xml" ,
> XmlWriteMode.WriteSchema );
>
> }
> }
>
>
>
> Thanks.
>



 
Reply With Quote
 
localhost
Guest
Posts: n/a
 
      16th Sep 2004

Thanks for the response. OK, so now I know I have to do a 2-step
process. I was afraid that was the case, but I wanted to know from
anyone with more experience (or MS knowledge) if it was possible to
get them all at once.

The Extended Properties in the DB contain info about each column that
can be used as contextual text in the GUI. So I need that info
stuffed into the ExtendedProperties collection at the DataColumn level
so it can be displayed on a form.

Thanks.




On Thu, 16 Sep 2004 17:08:58 +0200, "Patrice" <(E-Mail Removed)>
wrote:

>Not an MS engineer or MVP but I'll give it a try.
>
>It looks like you expect to have extended properties returned just by using
>a SELECT * FROM MaTable statement with the usual resultset. It just not the
>way it works.
>
>Remember that extended properties are tied to COLUMNS not ROWS. As such you
>won't find an additional column with the extended properties values (and
>that would have anyway the same value for all rows) as you seem to expect.
>You'll have to query extended properties separately. The result set will
>contains a row for each column and property.
>
>You may want to describe what you want to do with extended properties.
>
>IMO you'll have to do it as a two step process in your data layer :
>- have the data layer returning extended properties for each COLUMN (using
>fn_listextendedporperties)
>- then return ROWS (using SELECT * FROM MaTable)
>
>Hope it helps.


 
Reply With Quote
 
William \(Bill\) Vaughn
Guest
Posts: n/a
 
      16th Sep 2004
Did you read my article on Extended Properties?
http://www.betav.com/sql_server_magazine.htm
It might help clear up some issues.


--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________

"localhost" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>
> Thanks for the response. OK, so now I know I have to do a 2-step
> process. I was afraid that was the case, but I wanted to know from
> anyone with more experience (or MS knowledge) if it was possible to
> get them all at once.
>
> The Extended Properties in the DB contain info about each column that
> can be used as contextual text in the GUI. So I need that info
> stuffed into the ExtendedProperties collection at the DataColumn level
> so it can be displayed on a form.
>
> Thanks.
>
>
>
>
> On Thu, 16 Sep 2004 17:08:58 +0200, "Patrice" <(E-Mail Removed)>
> wrote:
>
>>Not an MS engineer or MVP but I'll give it a try.
>>
>>It looks like you expect to have extended properties returned just by
>>using
>>a SELECT * FROM MaTable statement with the usual resultset. It just not
>>the
>>way it works.
>>
>>Remember that extended properties are tied to COLUMNS not ROWS. As such
>>you
>>won't find an additional column with the extended properties values (and
>>that would have anyway the same value for all rows) as you seem to expect.
>>You'll have to query extended properties separately. The result set will
>>contains a row for each column and property.
>>
>>You may want to describe what you want to do with extended properties.
>>
>>IMO you'll have to do it as a two step process in your data layer :
>>- have the data layer returning extended properties for each COLUMN (using
>>fn_listextendedporperties)
>>- then return ROWS (using SELECT * FROM MaTable)
>>
>>Hope it helps.

>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
OleDbConnection extended properties m.trimble@verizon.net Microsoft ASP .NET 0 17th Mar 2006 09:13 PM
EXTENDED Attributes in PROPERTIES Tab Visum Windows XP Help 1 6th Jan 2006 11:28 AM
Extended properties =?iso-8859-1?q?Petter_J=F6nsson?= Windows XP Embedded 1 18th Feb 2005 09:45 AM
Extended Properties VJ Microsoft VB .NET 2 16th Mar 2004 10:30 PM
using sql extended properties ian Microsoft Access Database Table Design 0 7th Jul 2003 10:09 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:40 PM.