问题是从我的webservice获取dataGridView中的数据。当我从webservice调用getList方法时,我得到了正确的xml代码。 这是我的代码: 网络服务:
[WebMethod]
public DataSet getList()
{
SqlConnection connection = new SqlConnection();
connection.ConnectionString = "server=localhost;" +
"Trusted_Connection=yes;" +
"database=oving1; " +
"connection timeout=30";
string select = "select * from Person";
SqlDataAdapter da = new SqlDataAdapter(select, connection);
DataSet ds = new DataSet();
da.Fill(ds, "Person");
return (ds);
}
形式:
private void button1_Click(object sender, EventArgs e)
{
Service1 webService = new Service1();
DataSet ds = webService.getList();
dataGridView1.DataSource = ds;
}
答案 0 :(得分:3)
您最好查看此Avoiding DataSet in Web services
通过WebServices Consuming a DataSet from an XML Web Service
序列化数据集还有一件事是尝试将数据表传递给网格而不是数据集:
dataGridView1.DataSource = ds.Tables[0];