简体   繁体   中英

How can I deal with NULL values in data table turning into missing XML elements when inserting in SQL Server?

I want to insert data using XML in SQL Server 2005. So I got one datatable from the BackEnd and I passed the DataTable as follows;

     DataSet dsItem = new DataSet();
     DTItem.TableName = "ItemDetails";  //DTItem is the DataTable I got from the BackEnd
     dsItem.Tables.Add(DTItem);

My problem is, If any column contains null value then the XML not taking that null column. For ex: Consider this is my DataTable

     JobOrderID             CustomerID
    ------------           ------------
       4        

Here CustomerID is null. When I fix the Trace and View, the DataTable which shows empty instead of null. So. When I pass the DataTable, the XML does not consider the Null column. It takes as follows

 <NewDataSet>
   <ItemDetails>
      <JobOrderID>4</JobOrderID>
   </ItemDetails>
 </NewDataSet>

It is not taking CustomerID, So the insertion is not working. Why the DataTable does not show the Null values in the Column fields and How to pass if the DataTable containing null value as a XML? Please any suggestions.

I just solved this problem by assigning -1 instead of null . I know this is not the right solution, but I solved using this method.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM