Dataset Binding not working

I’d been working for 2 hours and yet I cannot figure out what is wrong with my code, I know that it is working because, when I invoke a method in my webservice it returns a result. Here is my script in my webservice;


[WebMethod]
public DataSet ViewList()
    {
        MySqlConnection cnDBConnection = new MySqlConnection();
        MySqlCommand cmRequestList = new MySqlCommand();
        MySqlDataAdapter daRequestList = new MySqlDataAdapter();
        DataSet dsRequestList = new DataSet();
        cnDBConnection.ConnectionString = clsVariables.strConnectionString;
        cnDBConnection.Open();
        cmRequestList.Connection = cnDBConnection;
        String strSQL = "SELECT lastname, firstname, middlename FROm person";
        cmRequestList.CommandText = strSQL;
        daRequestList.SelectCommand = cmRequestList;
        daRequestList.Fill(dsRequestList);
        return dsRequestList;
    }

Now in the page load of a certain page in my project I have this code


 wsPerson wPersonList = new wsPersons();
        grdRecord.AutoGenerateColumns = true;
        grdRecord.AutoGenerateSelectButton = true;
        grdRecord.AllowPaging = true;
        grdRecord.DataSource = wsPersons.ViewList();
        grdRecord.DataBind();

I am wondering why there are no records in my gridview, whereas, when I invoke the method in my webservice there are records. Can anyone help me, please.

It work, thanks to you guys. :slight_smile:

Yeah, NightStalker is correct, you need to bind to a table, as the Data Control dosen’t know which table to use (if you have multiple tables in a DataSet for example).

You can use the code above, but you can also use a named table, but it really ends the same way:

daRequestList.Fill(dsRequestList, “MyTable”);

wsPersons.ViewList().Tables[“MyTable”].DefaultView

Anal, yes :wink:

Wow, havent used datasets in ages. But I think you can only bind to a datatable.

wsPersons.ViewList().Tables[0].DefaultView or something like that. I cannot remember that well now though.