researching creating classes to hold commonly used methods, etc across
multiple WebForms. To a degree I understand this and managed to get a
"Hello World" example running where in my common.cs file I had:
public class dbConnection {
public const string iGreeting = "Hello World!";
}
and in my aspx files I simply put:
Response.Write(dbConnection.iGreeting.ToString());
what I'd like this method, dbConnection, to do is take a string (the
SQL Query, called 'sSQLQuery' (inventive, eh?)) and return a dataset.
my attempt failed (naturally, or I'd not be posting here), so I wonder
if a) this can be done at all, and b) what's wrong with my code (please
be gentle!!)
Expand|Select|Wrap|Line Numbers
- public object sReturnedDataSet() {
- string oradb = "Data Source=XXX;User Id=YYY;Password=ZZZ;";
- OracleConnection conn = new OracleConnection(oradb);
- // define the query & command
- string sSQLQuery = "SELECT * FROM table1";
- // define the command
- OracleCommand cmd = new OracleCommand(sSQLQuery,conn);
- // open the connection
- conn.Open();
- cmd.CommandType = CommandType.Text;
- OracleDataReader dr = cmd.ExecuteReader();
- return dr;
- }
Expand|Select|Wrap|Line Numbers
- Response.Write(dbConnection.sReturnedDataSet["field_name"].ToString();
browse the ASPX file, I got the following 'build' error:
'An object reference is required for the nonstatic field, method, or
property 'reports.dbConnection.sReturnedDataSet()'
can anyone help me out with some pointers, some sample code or a
website that might help explain it?
All help appreciated.