DataSet.WriteXML-替换DBNull [英] DataSet.WriteXML - Replace DBNull
问题描述
您好,我需要将数据集导出为XML,但是具有DBNull
值的每一列都会从最终的xml文件中消失!
Hello,I need to export a DataSet to XML but every column with DBNull
value disappears from the final xml file!
myDataAdapter.Fill(myDataSet, "info" ); myDataSet.WriteXml(dirpc + @"\gfmfinfo.xml" );
我需要找到一种方法来替换Fill&nb;之后的每个DBnull
值.这样每一行都会出现在xml文件中.是否有任何问题?
I need to find a way of replacing every DBnull
value after the Fill so that every column appeares in the xml file. Any sugestions?
推荐答案
我想显而易见的蛮力方法是没有问题的吗?在您从数据库请求数据时对数据进行清理怎么样?
I guess the obvious, brute force method is out of hte question ? How about sanitising your data at the point that you request it from the database ?
这是您可以做的一件事.您是否正在使用SQL填充此数据集?如果是这样,那么您可以编写SQL语句直接处理这些情况.使用ISNULL函数.因此,示例语句将是...
Here''s one thing you could do. Are you using SQL to fill this dataset? If so, then you can write the SQL statement to handle the cases directly. Use the ISNULL function. So a sample statement would be...
SELECT FieldThatWontBeNULL, ISNULL(FieldThatMightBeNULL,''Null Replacement'') as FieldThatMightBeNULL FROM MyTable
然后,您的数据集无需为此担心.如果需要动态设置此替换值,则可以将其替换为SQL语句(如果要以字符串形式生成),或者可以通过存储过程将其替换为参数.
如果您仍然需要帮助,请告诉我们
Then your dataset doesn''t need to worry about this. If you need to set this replacement value dynamically, you can just build it into your SQL statement if you are building as a string, or set it up as a parameter if you''re going via a stored procedure.
If you still need help, let us know
这篇关于DataSet.WriteXML-替换DBNull的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!