K
kevin
I'm new to C#, so forgive me if this is n00b stuff. I've been
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!!)
then I attempted to use this, like so:
However, this is where it went belly up and died on me. When I tried to
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.
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!!)
Code:
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;
}
then I attempted to use this, like so:
Code:
Response.Write(dbConnection.sReturnedDataSet["field_name"].ToString();
However, this is where it went belly up and died on me. When I tried to
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.