问题是从我的 web 服务获取我的 dataGridView 中的数据。当我从 web 服务调用 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;
}