G
Greg
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.DataSource = dsMyDataSource;
myGridView.DataBind();
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 = ConfigurationManager.ConnectionStrings
"DBName"].ConnectionString;
SqlConnection myConn = new SqlConnection(strConn);
string strSelectSQL = "SELECT * FROM tUser";
SqlCommand cmdUser = new SqlCommand(strSelectSQL, myConn);
SqlDataAdapter adpUser = new SqlDataAdapter();
adpUser.SelectCommand = cmdUser;
DataSet dsUser = new DataSet();
adpUser.Fill(dsUser);
return dsUser;
}
Now, I get an error "An object reference is required for the non-static
field, method, or property "UserComponents.UserDB.m_strConn"" 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
ObjectDataSource 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.DataSource using the procedure I
have above.
Thanks.
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.DataSource = dsMyDataSource;
myGridView.DataBind();
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 = ConfigurationManager.ConnectionStrings
"DBName"].ConnectionString;
SqlConnection myConn = new SqlConnection(strConn);
string strSelectSQL = "SELECT * FROM tUser";
SqlCommand cmdUser = new SqlCommand(strSelectSQL, myConn);
SqlDataAdapter adpUser = new SqlDataAdapter();
adpUser.SelectCommand = cmdUser;
DataSet dsUser = new DataSet();
adpUser.Fill(dsUser);
return dsUser;
}
Now, I get an error "An object reference is required for the non-static
field, method, or property "UserComponents.UserDB.m_strConn"" 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
ObjectDataSource 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.DataSource using the procedure I
have above.
Thanks.