title: Data binding a gridview using ObjectDataSource without Stored Procedure
body: <p>I have 1000 of records to display in the grid view so I am using ObjectDataSource to do binding to the grid view.  </p>
  
  <pre><code> &lt;asp:ObjectDataSource ID="odsProducts" runat="server" SelectMethod="GetProducts"
                  TypeName="ProductsList" EnablePaging="True"  MaximumRowsParameterName="PageSize"
                  SelectCountMethod="GetRowsCount" StartRowIndexParameterName="StartRow"&gt;&lt;/asp:ObjectDataSource&gt; 
  
                      &lt;asp:GridView ID="UserTable" runat="server" AllowPaging="True" DataSourceID="odsProducts"
                          SelectedIndex="0" DataKeyNames="UserID" ShowHeaderWhenEmpty="True" BorderStyle="Groove"
                          OnRowDataBound="UserTable_RowDataBound" AutoGenerateColumns="false"&gt;
  </code></pre>
  
  <p>In the Data access layer I have a class<code>[Dataserver]</code> which does the open and close connection, I have a method called executeNonQuery method which is used to retrieve data from the DB.</p>
  
  <pre><code>public int ExecuteNonQuery(CommandType commandType, string sql, MySqlParameter[] commandParameters)
  {
     ...
     return rowsAffected;
  }
  </code></pre>
  
  <p>So in my Getdata method of the OjectdataSource </p>
  
  <pre><code> private DataView GetData(int StartRow, int PageSize)
  {
    DataServer server = new DataServer();
    DataTable dt = new DataTable();
    int newOrgID = 60;
      string userQuery = "Select tbl_User.UserID, tbl_User.FirstName, tbl_User.LastName, tbl_User.Email, tbl_User.PhoneNumber, tbl_User.CreatedBy, tbl_Organisation.OrganisationName from tbl_user WHERE Organisationid=@OrganisationID order by tbl_user.LastName asc";
      MySqlParameter[] para = new MySqlParameter[1];
      para[0] = new MySqlParameter("@OrganisationID", MySqlDbType.Int32);
      para[0].Value = newOrgID ;
      dt = server.ExecuteQuery(CommandType.Text, userQuery, para);
  }
  </code></pre>
  
  <p>All the example in the web are with stored procedure can some one help me in doing this. The error I get here is I am not able to bind the grid view, cannot convert dataset into datable. So How can I use datatable to do the binding to the gridview</p>