为什么无法序列化数据表.未设置DataTable名称? [英] Why Cannot serialize the DataTable. DataTable name is not set ?

查看:887
本文介绍了为什么无法序列化数据表.未设置DataTable名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用此Web服务,但返回错误:

I am using this web service but returns error:

无法序列化数据表.未设置数据表名称.

Cannot serialize the DataTable. DataTable name is not set.

 [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);
        }

    }

我尝试了很多,但是没有用.

I tried a lot but doesn't work.

推荐答案

数据表只有在具有名称之前才能被序列化.要解决此错误,我们需要使用TableName属性为数据表提供名称.

data table can not be serialized until or unless it has a name. To resolve this error, we need to provide a name to the data table using the TableName property.

尝试为其命名,然后序列化:

try giving name to it then serialize :

     dt = GetData() //fill data
     dt.TableName = "MyDt"

这篇关于为什么无法序列化数据表.未设置DataTable名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆