此位置不允许有空格

问题描述:

专家,

我是Uday Satardekar.
我正在使用csharp
插入10000行
我正在使用xml发送批量数据.
但在某些情况下会抛出
此位置不允许有空白

我正在从excel中生成动态xml.

但是excel包含一些特殊字符,所以
错误在xml生成期间创建,我该如何解决和替换它
我在c Sharp中的代码是

Hi Expert,

I am Uday Satardekar.
i am inserting 10000 rows using csharp

i am using xml to send bulk data.
but in some situation it throws
white space is not allowed at this location error

i am generating dynamic xml from excel.

But excel contains some special character so
error is created during xml generation how i an solve and replace it
my code in c sharp is

StringBuilder XML_TRANSACTIONDETAILS = new StringBuilder();

XML_TRANSACTIONDETAILS.Append("<master>");
for (int i = 0; i < excelRows; i++)
{
    maxid = maxid + 1;

    XML_TRANSACTIONDETAILS.Append("<TRANSACTION>");
    XML_TRANSACTIONDETAILS.Append("<maxid>" + maxid + "</maxid>");

    for (int j = 0; j < ExcelColumnCount; j++)
    {
         string xmlTag = cleanedEmailTbl.Columns[j].ToString();


         XML_TRANSACTIONDETAILS.Append("<" + xmlTag + ">" + cleanedEmailTbl.Rows[i][j].ToString() + "</" + xmlTag + ">");
    }

    XML_TRANSACTIONDETAILS.Append("</TRANSACTION>");
}

XML_TRANSACTIONDETAILS.Append("</master>");






错误是:






and error is:

The error description is ''Whitespace is not allowed at this location.''.<br />
Could not find prepared statement with handle 0.<br />
Could not find prepared statement with handle 0.<br />
Could not find prepared statement with handle 0.<br />
sp_xml_removedocument: The value supplied for parameter number 1 is invalid.<br />
The statement has been terminated.<br />
The statement has been terminated.<br />
The statement has been terminated.



请告诉我如何删除

在此先感谢



Please tell me how to remove

thanks in advance

尝试以这种方式重写它,看看会发生什么

Try to rewrite it in this way and see what happens

for (int j = 0; j < ExcelColumnCount; j++)
{
    string xmlTag = cleanedEmailTbl.Columns[j].ToString().Trim();

    XML_TRANSACTIONDETAILS.AppendFormat("<{0}>{1}</{0}>", xmlTag, cleanedEmailTbl.Rows[i][j]);
}



让我们知道.



Let us know.


我怀疑您的xmlTag值偶尔会包含一个或多个空格字符.如果yu在调试器下运行它,并在引发异常时检查变量,则可以验证我的假设.

如果您的表中包含名称中带有空格的列,请您感到羞耻.只要您记得更改任何相关的存储的proc或代码内的SQL查询,就可以更改表中的有问题的列名.
I suspect that every once in a while your xmlTag value contains one or more whitespace characters). If yu run it under the debugger, and inspect the variable when it throws the exception, you can verify my assumption.

If your table contains columns with spaces in their names, shame on you. You can change the offending column names in the table as long as you remember to change any related stored procs or in-code sql queries.


谢谢您,先生.
它对我有用.
Thank you sir .
Its working for me.