我正在使用此网络服务但返回错误:
无法序列化 DataTable。 DataTable 名称未设置。
[WebMethod]
public DataTable ApprovalCertificate(int ID)
{
try
{
DatabaseConnection DatabaseConnection = new DatabaseConnection(Constants.Databases.BPAConnection);
SqlCommand SqlCom = new SqlCommand("ReportApprovalCertificate", DatabaseConnection.OpenConnection());
SqlCom.CommandType = CommandType.StoredProcedure;
SqlCom.Parameters.AddWithValue("@PropertyDetailsID", ID);
DataTable dt = new DataTable();
SqlDataAdapter sqlDA = new SqlDataAdapter(SqlCom);
sqlDA.Fill(dt);
DatabaseConnection.CloseConnection();
return dt;
}
catch (Exception ex)
{
throw ex;
}
finally
{
//ResultPanel.Controls.Add(ResultLabel);
}
}
我尝试了很多,但没有用。
最佳答案
数据表只有有名字才能被序列化。要解决此错误,我们需要使用 TableName 属性为数据表提供名称。
尝试给它命名然后序列化:
dt = GetData() //fill data
dt.TableName = "MyDt"
关于c# - 为什么无法序列化 DataTable。未设置数据表名称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38322181/