stianboe
stianboe

Reputation: 441

Getting data into dataGridView

The problem is getting data in my dataGridView from my webservice. When i invoke the getList method from the webservice i get the right xml code. This is my code: 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);
    }

form:

    private void button1_Click(object sender, EventArgs e)
    {

        Service1 webService = new Service1();
        DataSet ds = webService.getList();
        dataGridView1.DataSource = ds;


    }

Upvotes: 3

Views: 2995

Answers (1)

Amen Ayach
Amen Ayach

Reputation: 4348

You better check this Avoiding DataSet in Web services

To serialize Dataset over WebServices Consuming a DataSet from an XML Web Service

One more thing try to deliver a datatable to grid not dataset :

dataGridView1.DataSource = ds.Tables[0];

Upvotes: 3

Related Questions