嗨,我使用了下面的代码并将 XML 参数从 C# 传递给 sql server 得到以下错误“XML 解析:第 4 行,字符 19,文本/xmldecl 不在输入的开头”
<?xml version="1.0"?>
<ArrayOfInt xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<int>1</int>
</ArrayOfInt>
这是我的 C# 代码:
private void searchLeval1Language()
{
List<int> ClientId = new List<int>();
List<int> FieldId = new List<int>();
List<int> StatusId = new List<int>();
string[] Client = null;
Client = hdnClientID.Value.Split(',');
if (Client != null)
{
foreach (string s in Client)
{
if (!string.IsNullOrEmpty(s))
{
ClientId.Add(Convert.ToInt32(s));
}
}
}
string[] Field = null;
Field = hdnFieldID.Value.Split(',');
if (Field != null)
{
foreach (string s in Field)
{
if (!string.IsNullOrEmpty(s))
{
FieldId.Add(Convert.ToInt32(s));
}
}
}
XmlSerializer xs = new XmlSerializer(typeof(List<int>));
MemoryStream ms = new MemoryStream();
xs.Serialize(ms, ClientId);
string xmlClientid = UTF8Encoding.UTF8.GetString(ms.ToArray());
xs.Serialize(ms, FieldId);
string xmlFieldid = UTF8Encoding.UTF8.GetString(ms.ToArray());
xs.Serialize(ms, FieldId);
string xmlStatusid = UTF8Encoding.UTF8.GetString(ms.ToArray());
DataTable dtLangL2 = RetrievalProcedures.GetPartnerProfileIdforDashboardSearchLevel2(hdnL1toL2.Value, xmlClientid, xmlStatusid);
chLanguageL2.Series["LangSeriesL2"].XValueMember = "FieldName";
chLanguageL2.Series["LangSeriesL2"].YValueMembers = "cnt";
chLanguageL2.DataSource = dtLangL2;
chLanguageL2.DataBind();
}
这是将参数传递给数据库的代码
public static DataTable GetPartnerProfileIdforDashboardSearchLevel2(System.String language, System.String clientId, System.String statusProId)
{
// create parameters
SqlParameter[] parameters = new SqlParameter[3];
parameters[0] = new SqlParameter("@Language", SqlDbType.VarChar, 100, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, language);
parameters[1] = new SqlParameter("@ClientId", SqlDbType.Xml, 2147483647, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, clientId);
parameters[2] = new SqlParameter("@StatusProId", SqlDbType.Xml, 2147483647, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, statusProId);
// Call the stored proc.
DataTable toReturn = new DataTable("GetPartnerProfileIdforDashboardSearchLevel2");
bool hasSucceeded = DbUtils.CallRetrievalStoredProcedure("[JobApplicationModule].[dbo].[sp_GetPartnerProfileIdforDashboardSearchLevel2]", parameters, toReturn, null);
return toReturn;
}