Today, when doing the project, want to return to the DataTable in the WebService, in the unit did not succeed, see online Some people say datable in. net1.1 is not serialized, and cannot be returned directly in WebService, You can return a dataset. At night, I went to the internet to find a bit, see the Basic agreement, there is a lot of articles quoted in the asp.net2.0 that the DataTable has been serialized, But you also need to manually write some code to return from the webservice. I just want to write another code? Continue to search, found that some people say must give datable name can return, but also can be manually converted to the DataTable type on the caller. Did it again, completely, Without forcing the type to convert. The code is as follows:
In the WebService file
[WebMethod]
Public DataTable DT ()
{
DataTable dt = new DataTable ("Default");
Dt. Columns.Add ("id");
Dt. Columns.Add ("name");
for (int i = 0; i <; i++)
{
DataRow dr = dt. NewRow ();
dr["id"] = i.tostring ();
dr["name"] = "name" + i.tostring ();
Dt. Rows.Add (DR);
}
return DT;
}
In the call page
Webservice1.webservice1 service = new Webservice1.webservice1 ();
DataTable dt = Service.dt ();
Gvuser.datasource = DT;
Gvuser.databind ();
The key is to name the DataTable in the WebService method, otherwise it will be an error.