Determine datatype, column length info using SqlDataAdapter, XmlDataDocument classes in C#
-
Hello, This is my code which will convert the ADO resultset to XML in C#. I actually need the column type, column max length etc also in the xml, like the column type/length of id, loginuserid, deptid, wrkstnid etc. So I am not sure whether I need to pass some parameters to SqlDataAdapter class while executing the SQL command or the XmlDataDocument class has some methods which would print out the datatype and column length information in the XML. Looked at both the classes, didnt find any method, anybody has any ideas about this? Thanks DataSet ds = new DataSet(); SqlDataAdapter adapter = new SqlDataAdapter(cmd); adapter.Fill(ds); if (ds.Tables.Count>0) { _sBody = new StringBuilder("", _bodySize); //Get xml representation of the dataset XmlDataDocument srcXML = new XmlDataDocument(ds); srcXML.Save("c:\\XMLDocument.xml"); .... } 1tpmadmin11
2sysadmin22
-- modified at 12:25 Friday 5th May, 2006
-
Hello, This is my code which will convert the ADO resultset to XML in C#. I actually need the column type, column max length etc also in the xml, like the column type/length of id, loginuserid, deptid, wrkstnid etc. So I am not sure whether I need to pass some parameters to SqlDataAdapter class while executing the SQL command or the XmlDataDocument class has some methods which would print out the datatype and column length information in the XML. Looked at both the classes, didnt find any method, anybody has any ideas about this? Thanks DataSet ds = new DataSet(); SqlDataAdapter adapter = new SqlDataAdapter(cmd); adapter.Fill(ds); if (ds.Tables.Count>0) { _sBody = new StringBuilder("", _bodySize); //Get xml representation of the dataset XmlDataDocument srcXML = new XmlDataDocument(ds); srcXML.Save("c:\\XMLDocument.xml"); .... } 1tpmadmin11
2sysadmin22
-- modified at 12:25 Friday 5th May, 2006
Try this, (with 'ds' being your dataset) ds.WriteXml(@"c:\thedataset.xml",System.Data.XmlWriteMode.WriteSchema) ; That will write out all your xml with the schema.
-
Try this, (with 'ds' being your dataset) ds.WriteXml(@"c:\thedataset.xml",System.Data.XmlWriteMode.WriteSchema) ; That will write out all your xml with the schema.
Okay, I actually want the max size of the column and I think that information is missing in the XML. The XML looks something like this. Max size of the column is used by the XSL to print the data. For datatypes like int, numeric, datetime I can manage the column lenght, problem arises only when its of type string, char etc It has the column name, type, minOccurs. I think the max size of the column is missing, do I need to try some other method, or any other argument? Thanks, -- modified at 16:24 Friday 5th May, 2006