473,395 Members | 1,968 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,395 software developers and data experts.

Deserialize to DataSet - DataType ? acts like bug.

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
10 3989
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
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
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
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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Bob Rock | last post by:
Hello, I've got an xml stream that I'd need to deserialize into an instance of a given class A. I'd like to create an instance method on class A (method Deserialize) that takes this XML stream...
0
by: Thaddeus | last post by:
//Author: //Thaddeus Jacobs, MCP //Kinematic Automation, Inc. //mailto:tjacobs@kinematic.com // //Description: //convert ADO .NET dataset to ADO 2.5 2.6 2.7 recordset and v/v //DataSet to...
3
by: rawCoder | last post by:
Hi There, I simply want a DataGrid in .NET which acts .. well like the old VB6 grid .... where you fill and access elements directly ... not being dependant on some data source or DataSet to be...
0
by: Leo | last post by:
Thanks for the Help in Advance! I am a beginner in VB.Net. I am trying to create a form which is displayed in a email for our customers to fill in a Request for quote. I would like them to type...
22
by: Arne | last post by:
How do I pass a dataset to a webservices? I need to submit a shoppingcart from a pocket PC to a webservice. What is the right datatype? II have tried dataset as a datatype, but I can't get it to...
4
by: Samuel R. Neff | last post by:
I'm deserializing an XML file. If I pass a Stream to the file directly to the deserializer as follows it works fine: o = (New XmlSerializer( GetType(...
7
by: David P. Donahue | last post by:
My experience with databases using C# has been pretty limited thus far. Mostly I just use a SELECT statement to populate a DataSet, which is just read-only (mostly for display on a web page), or...
12
by: Andy B | last post by:
I need to custom build and use a dataset in c# to use with xml. Does anybody know where I can find out how to do something like this? I was going to create a class that generated the dataset and...
1
by: raghudr | last post by:
Hi all, I am parsing an .xml file.My main intention is to retrieve the field value:- "Name Value" which is "rag" and store it in a List. Fot that i wrote code like this: //i am using...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.