Return DataTable from Web Service
I know this is an old theme but I had to write a sample app for demonstration in a tech forum. So reproducing here also.
Importantly, the DataTable/DataSet must be serializable.
ASMX Code:
public class Service1 : System.Web.Services.WebService { [WebMethod] public DataTable HelloWorldDataSet() { DataTable dt = new DataTable("MyDataTable"); dt.Columns.Add("column1",typeof(System.String)); dt.Columns.Add("column2", typeof(System.String)); DataRow dr = dt.NewRow(); dr["column1"] = "blah1"; dr["column2"] = "blee1"; dt.Rows.Add(dr); dr = dt.NewRow(); dr["column1"] = "blah2"; dr["column2"] = "blee2"; dt.Rows.Add(dr); return dt; } }
private void button1_Click(object sender, EventArgs e) { helloservice.Service1 service = new WindowsFormsApplication1.helloservice.Service1(); DataTable dt = service.HelloWorldDataSet(); }
C# Code:
Related posts:























Leave a Reply
You must be logged in to post a comment.