Most of my background is with VB.Net and WinForm development and I am in the
process of migrating my skills to C# Web Based development. I've come across
something I'm not quite sure how I should handle.
I have a web-page with a asp:GridView on it. In hte Page_Load event of the
page, I create a Dataset and Bind it to the grid as follows:
myGridView.Data Source = dsMyDataSource;
myGridView.Data Bind();
Now, this works OK in testing, but I need to move the DataSource to come
from a module.
I've created a module that builds a DataSet call GetDataSet(); I've created
as follows:
public static DataSet GetDataSet()
{
string strConn = ConfigurationMa nager.Connectio nStrings
"DBName"].ConnectionStri ng;
SqlConnection myConn = new SqlConnection(s trConn);
string strSelectSQL = "SELECT * FROM tUser";
SqlCommand cmdUser = new SqlCommand(strS electSQL, myConn);
SqlDataAdapter adpUser = new SqlDataAdapter( );
adpUser.SelectC ommand = cmdUser;
DataSet dsUser = new DataSet();
adpUser.Fill(ds User);
return dsUser;
}
Now, I get an error "An object reference is required for the non-static
field, method, or property "UserComponents .UserDB.m_strCo nn"" m_strConn is
already a valid connection string as I am using it in other procedures in the
same module. What does this error mean?
I'm trying this approach because populating a GridView control using the
ObjectDataSourc e control does not allow me to provide sorting, so I'm looking
to populate the DataSource for the grid using a Dataset. I'm just not sure
how I can pass a DataSet to the gridControl.Dat aSource using the procedure I
have above.
Thanks.