IxiRancid Posted April 24, 2006 Posted April 24, 2006 I would like to get a table schema from my DB2 server. The usual methods with Iseries Navigator don't work, so I resorted to XML GetSchema. It actually works perfect, but I would need the Table's Field Descriptions in my XML Schema also! Are there any other ways I could achieve this? Quote
*Experts* Nerseus Posted April 24, 2006 *Experts* Posted April 24, 2006 Normally you would use a DataAdapter and a DataSet, but there are many methods. Here's a code snippet to get the schema for a table named Customer: // 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. I've 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 DataAdapter's Fill method. I've read articles that mention getting the schema through FillSchema is somewhat slow and shouldn't be used in production. I guess it depends on what you want the schema for... -nerseus Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
IxiRancid Posted April 25, 2006 Author Posted April 25, 2006 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 it's 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' Here's how I make my XSD's and later XML's (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() Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.