将数据加载到dataGridView中

3
问题在于我无法从WebService中获取dataGridView中的数据。当我调用webservice中的getList方法时,我可以得到正确的XML代码。 这是我的代码: Web Service:
[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;


    }

尝试将ds填充到数据表中,然后将此表链接到网格视图。 - Milee
ds是否按预期填充?请使用断点。 - SkonJeet
2
尝试使用dataGridView1.DataSource = ds.Tables [0],同时确保在设计中将autogeneratedcolumns设置为false,以防止自动生成列。 - Habib
1个回答

3

@Ravia,谢谢,但是stianboe只有13分,他还需要2分才能投票 ;) - Amen Ayach

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接