PC Review
Forums
Newsgroups
Microsoft DotNet
Microsoft ADO .NET
null value in xml translates to empty string in dataset after ReadXML
Forums
Newsgroups
Microsoft DotNet
Microsoft ADO .NET
null value in xml translates to empty string in dataset after ReadXML
![]() |
null value in xml translates to empty string in dataset after ReadXML |
|
|
Thread Tools | Rate Thread |
|
|
#1 |
|
Guest
Posts: n/a
|
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." |
|
|
|
#2 |
|
Guest
Posts: n/a
|
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" <belgie@datamti.com> wrote in message news:eGKI$%23vpIHA.3860@TK2MSFTNGP02.phx.gbl... >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." > > |
|
![]() |
|
| Thread Tools | |
| Rate This Thread | |
|
|

Main Page 

