Cuckoo
Cuckoo

Reputation: 177

Why Cannot serialize the DataTable. DataTable name is not set ?

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.

Upvotes: 1

Views: 7123

Answers (1)

Jayanti Lal
Jayanti Lal

Reputation: 1185

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"

Upvotes: 4

Related Questions