Can we return DataTable from WCF service?

Can we return DataTable from WCF service?

To return a DataTable using a WCF service, we must do the following 3 things: Create Database Table. Create WCF Service. Create a Web Application.

How do I return a DataTable?

Generic method to return data from database:

  1. public DataTable GetDataTable(string cnString, string sql)
  2. using (SqlConnection cn = new SqlConnection(cnString))
  3. using (SqlDataAdapter da = new SqlDataAdapter(sql, cn))
  4. DataSet ds = new DataSet();

How to send DataTable to WCF Service?

  1. You have to specify data table name like: MyTable=new DataTable(“tableName”);
  2. When you are adding reference on client side of WCF service select reusable dll system.data.
  3. Specify attribute on datatable member variable like [DataMember] public DataTable MyTable{ get; set; }

What is DataTable and DataSet in C#?

A DataTable is an in-memory representation of a single database table which has collection of rows and columns. 2.DataTable fetches only one TableRow at a time DataSet: 1.A DataSet is an in-memory representation of a database-like structure which has collection of DataTables.

What is the method of DataTable which can be used to retrieve information from DataTable?

QTP – Data Table Object Methods

Method Name Description
ExportSheet Exports a Specific Sheet of the Datatable in run-time
GetCurrentRow Returns the active row of the run-time data table of global sheet
GetParameterCount Returns the number of columns in the run-time data Table of Global Sheet

Why return type as DataTable is not working in WCF?

There are 3 reason for failed return type as datatablein WCF services You have to specify data table name like: MyTable=new DataTable(“tableName”); When you are adding reference on client side of WCF service select reusable dll system.data Specify attribute on datatablemember variable like

How to add reference to a DataTable in WCF service?

MyTable=new DataTable(“tableName”); When you are adding reference on client side of WCF service select reusable dll system.data Specify attribute on datatablemember variable like

How to return data from a SQL Server table as DataTable object?

In this article, we will see how to return data from a SQL Server table as a DataTable object using WCF service and consume it in a Console application. First, we will create a simple WCF service that will return data of the Employees table as a DataTable object. Then we will consume this WCF service in a Console application.

How to send data from WCF service to WCF web application?

The IService Interface class has a DataContract class named CustomerData which contains a DataTable Property CustomersTable which will be used to send the data from the WCF Service to the Web Application. The IService Interface has a method GetCustomers which is decorated with OperationContract attribute.