By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,784 Members | 2,933 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,784 IT Pros & Developers. It's quick & easy.

Deserialize to DataSet - DataType ? acts like bug.

P: n/a
I read in a earlier post that I can get the column of a grid to sort by datetime if the column type was set as Date

I deserialize my XML and one attribute of the XSD has type as dateTime but upon inspection and behavior in the gri
the data type is string. If I preview the dataset with the GUI in VISSTUDIO it shows my datatype to be dateTime ..

If I try to rest the datatype I get this erro
Additional information: Cannot change DataType of a column once it has data

This adds 2 new tables ..
FileStream finschema= new FileStream(schemaPath,FileMode.Open,FileAccess.Rea d,FileShare.Read)
ds.ReadXmlSchema(finschema);
finschema.Close()

Table
System.Strin
System.Strin
System.Strin
System.String // should have been dateTime !!
System.Strin
System.Strin
System.Int3
Table
System.Strin
System.Int3

Finally if If I try to rest the datatype I get this erro
Additional information: Cannot change DataType of a column once it has data

What's wrong ??? Thanks Andre

?xml version="1.0" encoding="UTF-8" ?><xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"><xs:element name="transactionrecord"><xs:complexType><xs:seque nce><xs:element ref="message" /></xs:sequence><xs:attribute name="customercode" type="xs:string" use="optional" /><xs:attribute name="model" type="xs:string" use="optional" /><xs:attribute name="documentid" type="xs:string" use="optional" /><xs:attribute name="transactiondate" type="xs:dateTime" use="optional" /><xs:attribute name="transactiontype" type="xs:string" use="optional" /></xs:complexType></xs:element><xs:element name="transactions"><xs:complexType><xs:sequence>< xs:element ref="transactionrecord" maxOccurs="unbounded" /></xs:sequence><xs:attribute name="application" type="xs:string" use="optional" /></xs:complexType></xs:element><xs:element name="message"></xs:element></xs:schema>
Nov 16 '05 #1
Share this Question
Share on Google+
10 Replies


P: n/a
Hi Andrew,

Based on my understanding, you want to read xml schema file into dataset,
which has a datetime column.

As you said, after read the schema file, you find that in VS.NET IDE
debugger, that column has the correct column data type: DateTime. But, what
does "upon inspection and behavior in the grid the data type is string"
mean? Where does the column data type view is string?

I have tested your sample code snippet and xml schema file, it works fine.
In debugger, I can view that the column's data type is DateTime. If I view
that column in PropertyGrid at runtime, the data type is also DateTime.

Also, I can re-set the column's data type freely without any problem(It
will also reflect in PropertyGrid at runtime). Like this:

ds.Tables[0].Columns[3].DataType=typeof(Int32);

Please clarify my little problem about this issue.

Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 16 '05 #2

P: n/a
Hi Jeff

What I said was that when I asked VS STudio to preview the XSD - it said the datatype would be dateTime - BUT when I actually ran the code, I was getting string - as my Console.writeline indicated

But you seem to get very different results ( and the results I would like to see ). So I will return again & try... Thanks
Nov 16 '05 #3

P: n/a
Hi Andrew,

Thanks for your feedback.

I will wait for your further test and feedback. Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 16 '05 #4

P: n/a
Hi Andrew,

Is your problem resolved? Do you still have any concern on this issue?

Please feel free to feedback. Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 16 '05 #5

P: n/a
OK I discovered the problem(s) - but I still need help. First was that although the explorer view showed a new XSD with type dateTime, the xsd being used was the one in the bin - apparently it does not sunchronize

Then I found that the transaction date I have in the XML is in a format that doesn't convert readily to dateTime. Oddly enough I used now() to save them. I made a copy of a sample xml data and replaced it with the string I found in an example at MSDN - theirs worked - mine did not

ex:
( MSDN copied value ) : transactiondate="2001-05-03
mine transactiondate="4/1/2004 1:32:12 PM"

So --- what do I do at this point ? - Any suggestions ? Stream the data in and reformat the attributes ..
But to what format ?? - I want to preserve the time as well as the date. It still seems like a bug if the
format was from NOW() and I need to manipulate it to read it back to dateTime. Am I missing something here

Try this file and it wont work
<?xml version="1.0"?><transactions xmlns:xsd="http://www.w3.org/2001/XMLSchema" application="QCMover" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><transactionrecord transactiondate="4/1/2004 1:32:12 PM" model="737-678" customercode="GOT" documentid="737-678_GOT_WDM_D280A112 " transactiontype="ERROR"><message>ProcessStateChang e found manual folder has Access ( book.ldb )locking file orphaned - or user in this PMA manual</message></transactionrecord></transactions

Thanks Andre

Nov 16 '05 #6

P: n/a
Hi Andrew,

Thanks very much for your feedback.

Do you use a strong typed dataset or a normal dataset? Do you use
DataSet.ReadXml or DataSet.ReaderXmlSchema method to read your sample xml
file?

If your dataset is strong typed, how do you define it? Can you paste some
code snippet for it?

Based on my understanding, in your xml file, if you use
transactiondate="2001-05-03" format, after reading into dataset,
"transactiondate" column's datatype is System.DateTime, while using
transactiondate="4/1/2004 1:32:12 PM" format, this column in DataSet is
System.String type(Which mean that .Net can not recognize this date time
format)

For strong typed dataset, the column's datatype is determined by the schema
in the xsd file, not automatic determined by the source xml file. If you
want to be determined by the source xml file, you may use un-typed dataset
to read the xml file. But I used the below sample code to read the xml
file, both date time format will result in "System.String" type:

private void button1_Click(object sender, System.EventArgs e)
{
DataSet ds=new DataSet();
string schemaPath="D:\\test.xml";
FileStream finschema= new
FileStream(schemaPath,FileMode.Open,FileAccess.Rea d,FileShare.Read);
ds.ReadXml(finschema);
finschema.Close();

MessageBox.Show
(ds.Tables[1].Columns["transactiondate"].DataType.ToString());
}

I will wait for your further feedback.

Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 16 '05 #7

P: n/a
Hi Andrew,

Thanks for your feedback.

I have reproduced out your problem, I will spend some time on it. I will
reply to you ASAP.

Thanks for your understanding.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 16 '05 #8

P: n/a
Hi Andrew,

After doing some research, I found this is by design, for the
implementation of DataSet, you can not use attribute as format yyyy/mm/dd,
so the FormatException will generate.

Workaround is simple, just use the correct format. I hope this help you.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 16 '05 #9

P: n/a
http://msdn.microsoft.com/library/de...rmatstrings.as

I am testing this and considering my options.....since now() is not a good format .... as its being generated

Thanks for trying the code ! I may have more questions - this was quite a surprise.
Nov 16 '05 #10

P: n/a
Hi Andrew,

Thanks for your feedback.

It is not that simple DateTime.Now does not work, but just the default
DateTime.ToString method use a string format that DataSet.ReadXml can not
recognize out.

As I think there are 2 workarounds for this issue:
one is using "yyyy-MM-ddTHH:mm:sszzzzzz" as format string paramter, then
use DateTime.Now.ToString(formatstring)
The other is do not use XSD to define it as System.DateTime type, but read
it in as System.String, then in later using just convert it to DateTime
type.

Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 16 '05 #11

This discussion thread is closed

Replies have been disabled for this discussion.