Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
SQL
ce
clients
clustering
connect
datamining
datawarehouse
dts
fulltext
jdbcdriver
msde
mseq
newusers
notificationsvcs
odbc
olap
programming
replication
reportingsvcs
security
securitytools
server
setup
sqlxml.viewmapper
tools
xml
  
 
date: Thu, 01 May 2008 15:18:42 -0500,    group: microsoft.public.sqlserver.ce        back       


ArgumentOutOfRangeException when using DataTable.WriteXML   
Hi, All!

I'm having a strange issue with DataTable.WriteXML. I've created a database with 
19 tables using an XML file that I read and process manually. Here is an excerpt 
from the table in question:

    <Loads PrimaryKey="OrderNumber,Segment">
       <Field Name="OrderNumber" Type="nvarchar" Size="30" />
       <Field Name="Segment" Type="int" Size="" />
       <Field Name="LoadTypeID" Type="nvarchar" Size="3" />
       <Field Name="MinLoadDate" Type="datetime" Size="" />
       <Field Name="MaxLoadDate" Type="datetime" Size="" />
       <Field Name="LoadDate" Type="datetime" Size="" />
       <Field Name="DeliverDate" Type="datetime" Size="" />
       <Field Name="ShipperName" Type="nvarchar" Size="30" />
       <Field Name="Consignee" Type="nvarchar" Size="30" />
       <Field Name="OriginAgentNumber" Type="nvarchar" Size="6" />
       <Field Name="OriginAgentName" Type="nvarchar" Size="50" />
       <Field Name="OriginAddress" Type="nvarchar" Size="40" />
       <Field Name="OriginCity" Type="nvarchar" Size="30" />
       <Field Name="OriginState" Type="nchar" Size="2" />
       <Field Name="OriginPostalCode" Type="nvarchar" Size="10" />
       <Field Name="HaulingAgentNumber" Type="nvarchar" Size="6" />
       <Field Name="DestAddress" Type="nvarchar" Size="40" />
       <Field Name="DestCity" Type="nvarchar" Size="30" />
       <Field Name="DestState" Type="nchar" Size="2" />
       <Field Name="DestPostalCode" Type="nvarchar" Size="10" />
       <Field Name="DestContactName" Type="nvarchar" Size="30" />
       <Field Name="DestContactPhone" Type="nvarchar" Size="21" />
       <Field Name="CarrierName" Type="nvarchar" Size="30" />
       <Field Name="CarrierICC" Type="nvarchar" Size="9" />
       <Field Name="CarrierUSDOT" Type="nvarchar" Size="10" />
       <Field Name="TruckNumber" Type="nvarchar" Size="255" />
       <Field Name="TrailerNumber" Type="nvarchar" Size="255" />
       <Field Name="SetoffAgent" Type="nvarchar" Size="6" />
       <Field Name="SetoffAddress" Type="nvarchar" Size="40" />
       <Field Name="SetoffCity" Type="nvarchar" Size="30" />
       <Field Name="SetoffState" Type="nchar" Size="2" />
       <Field Name="SetoffPostalCode" Type="nvarchar" Size="10" />
       <Field Name="ContractNumber" Type="nvarchar" Size="15" />
       <Field Name="DriverID" Type="nvarchar" Size="255" />
       <Field Name="TripNumber" Type="nvarchar" Size="11" />
       <Field Name="TagColorID" Type="nchar" Size="1" />
       <Field Name="Comments" Type="nvarchar" Size="1024" />
       <Field Name="StopNumber" Type="nvarchar" Size="2" />
       <Field Name="Loaded" Type="bit" Size="" />
       <Field Name="Delivered" Type="bit" Size="" />
       <Field Name="Verified" Type="bit" Size="" />
       <Field Name="MissingItems" Type="bit" Size="" />
       <Field Name="WarehouseLoad" Type="bit" Size="" />
       <Field Name="PackersInventory" Type="bit" Size="" />
       <Field Name="DriverOriginated" Type="bit" Size="" />
    </Loads>

My application takes this file and generates the appropriate SQL "create table" 
command with a primary key of (OrderNumber,Segment).

When the application finishes, I call (Loads).WriteXML(stream, 
XmlWriteMode.[IgnoreSchema/WriteSchema]). When I do this, it immediately throws 
an ArgumentOutOfRangeException with the message: "Specified argument was out of 
the range of valid values." I've done this with another table and it writes the 
data with no problem (the structure is 2 nvarchar's and 1 bit).

For the life of me, I cannot see why this is happening. I've checked lengths of 
data against the physical length of the field, ampersands in the data that might 
cause problems in the XML, null vs not-null values (everything has a value, even 
though it might not have one in a realistic environment), properly formatted 
date values.... Everything looks like it is set and formatted correctly.

I've even done this same thing in a PC (DOS) version of the code and it works fine.

I've setup some relationships between several tables. Could this be causing the 
problem? I'm only trying to write the data from a single table.

Why??

Thanks in advance for your help,
Kevin
date: Thu, 01 May 2008 15:18:42 -0500   author:   Kevin

Re: ArgumentOutOfRangeException when using DataTable.WriteXML   
Apparently, the WriteXML function does not like DateTime values. The value I'm 
using is from a DateTimePicker. I'm using both the Value and the Text 
properties. When I look at the DataRow values for the datetime fields, it looks 
like the values in the record are correct. It's only when I try to write them to 
  XML that they don't get accepted as valid values. If I use DBNull.Value as the 
value, then there is no problem.

How should I write a DateTime value to the field so this does not happen?

Thanks,
Kevin


Kevin wrote:
> Hi, All!
> 
> I'm having a strange issue with DataTable.WriteXML. I've created a 
> database with 19 tables using an XML file that I read and process 
> manually. Here is an excerpt from the table in question:
> 
>    <Loads PrimaryKey="OrderNumber,Segment">
>       <Field Name="OrderNumber" Type="nvarchar" Size="30" />
>       <Field Name="Segment" Type="int" Size="" />
>       <Field Name="LoadTypeID" Type="nvarchar" Size="3" />
>       <Field Name="MinLoadDate" Type="datetime" Size="" />
>       <Field Name="MaxLoadDate" Type="datetime" Size="" />
>       <Field Name="LoadDate" Type="datetime" Size="" />
>       <Field Name="DeliverDate" Type="datetime" Size="" />
>       <Field Name="ShipperName" Type="nvarchar" Size="30" />
>       <Field Name="Consignee" Type="nvarchar" Size="30" />
>       <Field Name="OriginAgentNumber" Type="nvarchar" Size="6" />
>       <Field Name="OriginAgentName" Type="nvarchar" Size="50" />
>       <Field Name="OriginAddress" Type="nvarchar" Size="40" />
>       <Field Name="OriginCity" Type="nvarchar" Size="30" />
>       <Field Name="OriginState" Type="nchar" Size="2" />
>       <Field Name="OriginPostalCode" Type="nvarchar" Size="10" />
>       <Field Name="HaulingAgentNumber" Type="nvarchar" Size="6" />
>       <Field Name="DestAddress" Type="nvarchar" Size="40" />
>       <Field Name="DestCity" Type="nvarchar" Size="30" />
>       <Field Name="DestState" Type="nchar" Size="2" />
>       <Field Name="DestPostalCode" Type="nvarchar" Size="10" />
>       <Field Name="DestContactName" Type="nvarchar" Size="30" />
>       <Field Name="DestContactPhone" Type="nvarchar" Size="21" />
>       <Field Name="CarrierName" Type="nvarchar" Size="30" />
>       <Field Name="CarrierICC" Type="nvarchar" Size="9" />
>       <Field Name="CarrierUSDOT" Type="nvarchar" Size="10" />
>       <Field Name="TruckNumber" Type="nvarchar" Size="255" />
>       <Field Name="TrailerNumber" Type="nvarchar" Size="255" />
>       <Field Name="SetoffAgent" Type="nvarchar" Size="6" />
>       <Field Name="SetoffAddress" Type="nvarchar" Size="40" />
>       <Field Name="SetoffCity" Type="nvarchar" Size="30" />
>       <Field Name="SetoffState" Type="nchar" Size="2" />
>       <Field Name="SetoffPostalCode" Type="nvarchar" Size="10" />
>       <Field Name="ContractNumber" Type="nvarchar" Size="15" />
>       <Field Name="DriverID" Type="nvarchar" Size="255" />
>       <Field Name="TripNumber" Type="nvarchar" Size="11" />
>       <Field Name="TagColorID" Type="nchar" Size="1" />
>       <Field Name="Comments" Type="nvarchar" Size="1024" />
>       <Field Name="StopNumber" Type="nvarchar" Size="2" />
>       <Field Name="Loaded" Type="bit" Size="" />
>       <Field Name="Delivered" Type="bit" Size="" />
>       <Field Name="Verified" Type="bit" Size="" />
>       <Field Name="MissingItems" Type="bit" Size="" />
>       <Field Name="WarehouseLoad" Type="bit" Size="" />
>       <Field Name="PackersInventory" Type="bit" Size="" />
>       <Field Name="DriverOriginated" Type="bit" Size="" />
>    </Loads>
> 
> My application takes this file and generates the appropriate SQL "create 
> table" command with a primary key of (OrderNumber,Segment).
> 
> When the application finishes, I call (Loads).WriteXML(stream, 
> XmlWriteMode.[IgnoreSchema/WriteSchema]). When I do this, it immediately 
> throws an ArgumentOutOfRangeException with the message: "Specified 
> argument was out of the range of valid values." I've done this with 
> another table and it writes the data with no problem (the structure is 2 
> nvarchar's and 1 bit).
> 
> For the life of me, I cannot see why this is happening. I've checked 
> lengths of data against the physical length of the field, ampersands in 
> the data that might cause problems in the XML, null vs not-null values 
> (everything has a value, even though it might not have one in a 
> realistic environment), properly formatted date values.... Everything 
> looks like it is set and formatted correctly.
> 
> I've even done this same thing in a PC (DOS) version of the code and it 
> works fine.
> 
> I've setup some relationships between several tables. Could this be 
> causing the problem? I'm only trying to write the data from a single table.
> 
> Why??
> 
> Thanks in advance for your help,
> Kevin
date: Thu, 01 May 2008 15:52:16 -0500   author:   Kevin

Re: ArgumentOutOfRangeException when using DataTable.WriteXML   
On May 1, 3:52 pm, Kevin  wrote:
> Apparently, the WriteXML function does not like DateTime values. The value I'm
> using is from a DateTimePicker. I'm using both the Value and the Text
> properties. When I look at the DataRow values for the datetime fields, it looks
> like the values in the record are correct. It's only when I try to write them to
>   XML that they don't get accepted as valid values. If I use DBNull.Value as the
> value, then there is no problem.
>
> How should I write a DateTime value to the field so this does not happen?
>
> Thanks,
> Kevin
>
> Kevin wrote:
> > Hi, All!
>
> > I'm having a strange issue with DataTable.WriteXML. I've created a
> > database with 19 tables using an XML file that I read and process
> > manually. Here is an excerpt from the table in question:
>
> >    <Loads PrimaryKey="OrderNumber,Segment">
> >       <Field Name="OrderNumber" Type="nvarchar" Size="30" />
> >       <Field Name="Segment" Type="int" Size="" />
> >       <Field Name="LoadTypeID" Type="nvarchar" Size="3" />
> >       <Field Name="MinLoadDate" Type="datetime" Size="" />
> >       <Field Name="MaxLoadDate" Type="datetime" Size="" />
> >       <Field Name="LoadDate" Type="datetime" Size="" />
> >       <Field Name="DeliverDate" Type="datetime" Size="" />
> >       <Field Name="ShipperName" Type="nvarchar" Size="30" />
> >       <Field Name="Consignee" Type="nvarchar" Size="30" />
> >       <Field Name="OriginAgentNumber" Type="nvarchar" Size="6" />
> >       <Field Name="OriginAgentName" Type="nvarchar" Size="50" />
> >       <Field Name="OriginAddress" Type="nvarchar" Size="40" />
> >       <Field Name="OriginCity" Type="nvarchar" Size="30" />
> >       <Field Name="OriginState" Type="nchar" Size="2" />
> >       <Field Name="OriginPostalCode" Type="nvarchar" Size="10" />
> >       <Field Name="HaulingAgentNumber" Type="nvarchar" Size="6" />
> >       <Field Name="DestAddress" Type="nvarchar" Size="40" />
> >       <Field Name="DestCity" Type="nvarchar" Size="30" />
> >       <Field Name="DestState" Type="nchar" Size="2" />
> >       <Field Name="DestPostalCode" Type="nvarchar" Size="10" />
> >       <Field Name="DestContactName" Type="nvarchar" Size="30" />
> >       <Field Name="DestContactPhone" Type="nvarchar" Size="21" />
> >       <Field Name="CarrierName" Type="nvarchar" Size="30" />
> >       <Field Name="CarrierICC" Type="nvarchar" Size="9" />
> >       <Field Name="CarrierUSDOT" Type="nvarchar" Size="10" />
> >       <Field Name="TruckNumber" Type="nvarchar" Size="255" />
> >       <Field Name="TrailerNumber" Type="nvarchar" Size="255" />
> >       <Field Name="SetoffAgent" Type="nvarchar" Size="6" />
> >       <Field Name="SetoffAddress" Type="nvarchar" Size="40" />
> >       <Field Name="SetoffCity" Type="nvarchar" Size="30" />
> >       <Field Name="SetoffState" Type="nchar" Size="2" />
> >       <Field Name="SetoffPostalCode" Type="nvarchar" Size="10" />
> >       <Field Name="ContractNumber" Type="nvarchar" Size="15" />
> >       <Field Name="DriverID" Type="nvarchar" Size="255" />
> >       <Field Name="TripNumber" Type="nvarchar" Size="11" />
> >       <Field Name="TagColorID" Type="nchar" Size="1" />
> >       <Field Name="Comments" Type="nvarchar" Size="1024" />
> >       <Field Name="StopNumber" Type="nvarchar" Size="2" />
> >       <Field Name="Loaded" Type="bit" Size="" />
> >       <Field Name="Delivered" Type="bit" Size="" />
> >       <Field Name="Verified" Type="bit" Size="" />
> >       <Field Name="MissingItems" Type="bit" Size="" />
> >       <Field Name="WarehouseLoad" Type="bit" Size="" />
> >       <Field Name="PackersInventory" Type="bit" Size="" />
> >       <Field Name="DriverOriginated" Type="bit" Size="" />
> >    </Loads>
>
> > My application takes this file and generates the appropriate SQL "create
> > table" command with a primary key of (OrderNumber,Segment).
>
> > When the application finishes, I call (Loads).WriteXML(stream,
> > XmlWriteMode.[IgnoreSchema/WriteSchema]). When I do this, it immediately
> > throws an ArgumentOutOfRangeException with the message: "Specified
> > argument was out of the range of valid values." I've done this with
> > another table and it writes the data with no problem (the structure is 2
> > nvarchar's and 1 bit).
>
> > For the life of me, I cannot see why this is happening. I've checked
> > lengths of data against the physical length of the field, ampersands in
> > the data that might cause problems in the XML, null vs not-null values
> > (everything has a value, even though it might not have one in a
> > realistic environment), properly formatted date values.... Everything
> > looks like it is set and formatted correctly.
>
> > I've even done this same thing in a PC (DOS) version of the code and it
> > works fine.
>
> > I've setup some relationships between several tables. Could this be
> > causing the problem? I'm only trying to write the data from a single table.
>
> > Why??
>
> > Thanks in advance for your help,
> > Kevin

I recall having some issues with DateTime data type when dealing with
Webservices in the past.  Since Webservices use XML to exchange data,
it just may be related.  In the end, I had to convert the DateTime to
String via ToString() in order to make it work.  Not really sure why
it didn't like the DateTime format in the first place.  See if similar
approach works for you.

- Jin
date: Fri, 2 May 2008 09:33:02 -0700 (PDT)   author:   Jin

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us