oracle c# select query code example
Example 1: oracle c# select query
public List<Donor> Get()
{
List<Donor> donors = new List<Donor>();
string query;
OracleCommand cmd;
OracleDataReader reader;
query = "SELECT * FROM ldhc_accounts l JOIN donors d ON l.donor_id = d.id";
conn.Open();
cmd = new OracleCommand(query, conn);
reader = cmd.ExecuteReader();
while (reader.Read())
{
Donor d = new Donor();
{
d.DonorId = Convert.ToInt32(reader["id"]);
d.FName = reader["fname"].ToString();
donors.Add(d);
}
}
conn.Close();
return donors;
}
Example 2: c# select oracle database
DataSet ds = new DataSet();
using(OracleConnection con = new OracleConnection(connectionstr))
{
using(OracleCommand cmd = con.CreateCommand())
{
con.Open();
cmd.CommandText = "SELECT * FROM all_users";
OracleDataAdapter adap = new OracleDataAdapter(cmd);
adap.Fill(ds);
}
}