473,396 Members | 2,010 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.

Generating XML Schema for SQL Server Table

how can persist schema for a sql server table into an xml file from .net
application?

thanks
Mar 24 '07 #1
4 6994
PS

"Job Lot" <Jo****@discussions.microsoft.comwrote in message
news:CA**********************************@microsof t.com...
how can persist schema for a sql server table into an xml file from .net
application?
There are probably many ways to do this. Some quick overviews and then I can
give you more details.

1. Sql Server can provide XML based information that you can use
SqlXmlCommand. I use this to create an XML schema of my complete database
from which I apply an XLST to and generate code from this. This is used when
I know nothing about my database at all, not even a table name.

2. If you know a table name it has some data then you can SELECT TOP 1 *
FROM TableName and then while reading the first row using SqlDataReader you
can get the field count and then get the column name and column type and
create an XML file from this information.

3. I believe that if you have a strongly typed dataset then you can get
schema information but then if you already have the typed dataset then you
probably already have the information you need.

The best answer is probably where and how the information is being used,
e.g. during development, in a production environment, is the table
information dynamic or can you setup your application ahead of time with a
typed dataset.

PS
Mar 25 '07 #2
Here you go...

Two Tables in one dataset:

Dim cn As SqlConnection = _
New SqlConnection(My.Settings.NorthwindConnectionStrin g)
cn.Open()
Dim SQLString As String = _
"SELECT CustomerID, CompanyName FROM Customers;" & _
"SELECT OrderID, CustomerID, OrderDate FROM Orders"

Dim da As SqlDataAdapter = New SqlDataAdapter(SQLString, cn)
da.TableMappings.Add("Table", "Customers")
da.TableMappings.Add("Table1", "Orders")
Dim ds As DataSet = New DataSet("NWDataSet")
da.FillSchema(ds, SchemaType.Mapped)
ds.Relations.Add("Customers_Orders", _
ds.Tables("Customers").Columns("CustomerID"), _
ds.Tables("Orders").Columns("CustomerID"))
ds.WriteXmlSchema("E:\NWDataSet.XSD")

One table in a dataset:

Dim da2 As SqlDataAdapter = _
New SqlDataAdapter("SELECT * FROM Customers", cn)
da2.TableMappings.Add("Table", "Customers")
Dim ds2 As DataSet = New DataSet("NWCustomerDataSet")
da2.FillSchema(ds2, SchemaType.Mapped)
ds2.WriteXmlSchema("E:\NWCustomerDataSet.XSD")
cn.Close()

Robin S.
---------------------------------------
"Job Lot" <Jo****@discussions.microsoft.comwrote in message
news:CA**********************************@microsof t.com...
how can persist schema for a sql server table into an xml file from .net
application?

thanks

Mar 26 '07 #3
I am intending to use BulkLoad for restoring database from an XML file.
BulkLoad requires schema file as one of the arguments.

"PS" wrote:
>
"Job Lot" <Jo****@discussions.microsoft.comwrote in message
news:CA**********************************@microsof t.com...
how can persist schema for a sql server table into an xml file from .net
application?

There are probably many ways to do this. Some quick overviews and then I can
give you more details.

1. Sql Server can provide XML based information that you can use
SqlXmlCommand. I use this to create an XML schema of my complete database
from which I apply an XLST to and generate code from this. This is used when
I know nothing about my database at all, not even a table name.

2. If you know a table name it has some data then you can SELECT TOP 1 *
FROM TableName and then while reading the first row using SqlDataReader you
can get the field count and then get the column name and column type and
create an XML file from this information.

3. I believe that if you have a strongly typed dataset then you can get
schema information but then if you already have the typed dataset then you
probably already have the information you need.

The best answer is probably where and how the information is being used,
e.g. during development, in a production environment, is the table
information dynamic or can you setup your application ahead of time with a
typed dataset.

PS
Mar 28 '07 #4
PS

"Job Lot" <Jo****@discussions.microsoft.comwrote in message
news:5E**********************************@microsof t.com...
>I am intending to use BulkLoad for restoring database from an XML file.
BulkLoad requires schema file as one of the arguments.
You are wanting to import an XML file into your database? You can also use
bcp with an XML file.
>
"PS" wrote:
>>
"Job Lot" <Jo****@discussions.microsoft.comwrote in message
news:CA**********************************@microso ft.com...
how can persist schema for a sql server table into an xml file from
.net
application?

There are probably many ways to do this. Some quick overviews and then I
can
give you more details.

1. Sql Server can provide XML based information that you can use
SqlXmlCommand. I use this to create an XML schema of my complete database
from which I apply an XLST to and generate code from this. This is used
when
I know nothing about my database at all, not even a table name.

2. If you know a table name it has some data then you can SELECT TOP 1 *
FROM TableName and then while reading the first row using SqlDataReader
you
can get the field count and then get the column name and column type and
create an XML file from this information.

3. I believe that if you have a strongly typed dataset then you can get
schema information but then if you already have the typed dataset then
you
probably already have the information you need.

The best answer is probably where and how the information is being used,
e.g. during development, in a production environment, is the table
information dynamic or can you setup your application ahead of time with
a
typed dataset.

PS

Mar 28 '07 #5

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

Similar topics

4
by: Justin Lebar | last post by:
Sorry about the huge post, but I think this is the amount of information necessary for someone to help me with a good answer. I'm writing a statistical analysis program in ASP.net and MSSQL7 that...
5
by: Jon Sequeira | last post by:
Does anyone know of a component or class that available for generating updategrams from custom business objects? Ideally I need something that parses a mapping schema, interrogates an object, and...
12
by: Martin_Hurst | last post by:
Has some one come up with a similar type script that could be used in a Postgresql database? The script below was created for a SQLServer database. Thx, -Martin ...
3
by: Ram | last post by:
Hi, How can i generate an XSD for a set of SQL Server tables(i have three tables. One table is parent of other two tables.) programatically or using a tool. Thanks in advance. Regards, Sairam
2
by: Usha Vas | last post by:
Hi, I had posted this question in donet.framework.adonet but thought it might make more sense here, so I apologize for the duplicate post. I have an XML schema with one of the elements (Sig)...
10
by: Al Christoph | last post by:
Please forgive me if this is the wrong place to post this. The last place I posted got me a fairly rude response. I guess vb.db people just don't want to think about XML as database. At any rate,...
1
by: Noor | last post by:
Hi all I need to generate xml schmea for a stored procedures to use with crystal reports tell me any quick and easy method. thanks
1
by: louis_la_brocante | last post by:
Dear all, I am having trouble generating a client proxy for a webservice whose methods return a "complex" type. The type is complex in that it is a class whose members are a mix of primitive...
13
by: Martin Z | last post by:
I'm making a CRUD screen for an Oracle database... but problem is that the primary key in that table is populated via an autonumber, which in Oracle is done just with triggers and sequences. ...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.