PC Review


Reply
Thread Tools Rate Thread

null value in xml translates to empty string in dataset after ReadXML

 
 
BillE
Guest
Posts: n/a
 
      25th Apr 2008
I am importing data in a XML document into a SQL Server database.

Null data in the XML document is represented like this:
<elementname />

But when I load the XML document into a dataset, it becomes an empty string,
which generates an error when I insert the data into the database for
datetime fields.

I load the data into a XMLTextReader, read it into a dataset, and send it to
the database:

XMLTextReader xr = new XMLTextReader (filename.xml);
DataSet ds = new DataSet();
ds.ReadXML(xr);
SQLDataAdapter da = new SQLDataAdapter();
//configure InsertCommand...
da.Update(ds);

When I look at the data in the dataset, null values in elements become empty
strings "". I get:

"Failed to convert parameter value from a String to a DateTime."


 
Reply With Quote
 
 
 
 
Scott M.
Guest
Posts: n/a
 
      25th Apr 2008
And your question was?

XML is about text, so it's no surprise that nulls are handled this way (no
text equals empty string).

You'll need to iterate your DataSet and check for this scenario or use a
Schema with your DataSet to avoid it.

-Scott

"BillE" <(E-Mail Removed)> wrote in message
news:eGKI$%(E-Mail Removed)...
>I am importing data in a XML document into a SQL Server database.
>
> Null data in the XML document is represented like this:
> <elementname />
>
> But when I load the XML document into a dataset, it becomes an empty
> string, which generates an error when I insert the data into the database
> for datetime fields.
>
> I load the data into a XMLTextReader, read it into a dataset, and send it
> to the database:
>
> XMLTextReader xr = new XMLTextReader (filename.xml);
> DataSet ds = new DataSet();
> ds.ReadXML(xr);
> SQLDataAdapter da = new SQLDataAdapter();
> //configure InsertCommand...
> da.Update(ds);
>
> When I look at the data in the dataset, null values in elements become
> empty strings "". I get:
>
> "Failed to convert parameter value from a String to a DateTime."
>
>



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Dataset.ReadXml: M/c hangs when trying to read 37mb xml string. =?Utf-8?B?U2F2dnk=?= Microsoft ADO .NET 5 11th Sep 2006 06:16 PM
Readxml diffgram: returns empty dataset Mav Microsoft ADO .NET 0 28th Jan 2005 04:45 PM
Empty (NUll) value in cell, not empty string? Jan Kronsell Microsoft Excel Discussion 4 20th Nov 2004 06:09 PM
DataSet.ReadXml and Empty Elements creating duplicate data Alejandro Calbazana Microsoft ADO .NET 0 3rd Sep 2003 10:15 PM
avoiding Null Values in dataset.table and set them to empty string or 0 Anton Sommer Microsoft ADO .NET 5 27th Aug 2003 01:57 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:17 PM.