XML GetSchema

IxiRancid

Well-known member
Joined
Jun 16, 2004
Messages
104
Location
Europe
I would like to get a table schema from my DB2 server. The usual methods with Iseries Navigator dont work, so I resorted to XML GetSchema.
It actually works perfect, but I would need the Tables Field Descriptions in my XML Schema also!

Are there any other ways I could achieve this?
 
Normally you would use a DataAdapter and a DataSet, but there are many methods. Heres a code snippet to get the schema for a table named Customer:
C#:
// Assumes a using statement at the top:
// using System.Data.SqlClient;
SqlDataAdapter adapter = new SqlDataAdapter("SELECT TOP 1 * FROM Customer", "<connection string here>");
DataSet ds = new DataSet();
adapter.FillSchema(ds, SchemaType.Source, "Cust");

Note that the string "Cust" used in the FillSchema method will be the name of the table in the DataSet. The schema is based 100% on the SelectCommand. Ive seen some people use "... WHERE 1 = 0" in place of the "TOP 1" to prevent any rows from being returned. You can use whatever you like.

If you need to actually get the data AND the schema, then use the DataAdapters Fill method.

Ive read articles that mention getting the schema through FillSchema is somewhat slow and shouldnt be used in production. I guess it depends on what you want the schema for...

-nerseus
 
Actually that is what I already have, let me explain why I need this:
- the company where I work needs some kind of Technical documentation about our software and we were given the assignment of creating a Relation diagram with additional explanation of the tables and its structures.

I would need the field description of each field in our tables:
filed name - type - description
CONO - INT - Company number
CNME - CHAR(50) - Company name

Heres how I make my XSDs and later XMLs (ds being a filled DataSet)

swXMLschema = New StreamWriter(knjiznica & "_" & DB2file & ".xsd")
Dim srSchema As String = ds.GetXmlSchema
Dim srReplace1 As String
srReplace1 = srSchema.Replace("Table", DB2file)
srReplace1 = srReplace1.Replace("utf-16", "windows-1250")
swXMLschema.Write(srReplace1)
Me.TextBox1.Text = srReplace1
swXMLschema.Close()
 
Back
Top