-I have a simple select statement (with a join) of two tables.
-While the reader is reading this, I'm creating a new instance, and then calling my classes that will contain the information from each of my table columns.
-Then, I'm adding this instance at the end of the list.
BUT after weeks of debugging, I've realized that for some reason, a new instance of 'd' in this case, isn't being created. So, each time it goes through retrieving the information from the classes, it simultaneously replaces the previous array in the list. This results in the same row being produced each time. Here is my code.
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;
}
C# File:
protected void get_donors_btn_Click(object sender, EventArgs e)
{
List<Donor> donors = a_oracle.Get();
foreach(Donor item in donors)
{
get_donors.InnerHtml += "<li>"
+ item.DonorId + " "
+ item.FName + " "
+ "</li>";
}
}
Donors Class
namespace FinalProj.Models
{
public class Donor : ldhc
{
private static Int64 _donor_credit_card;
private static int _donor_ccv;
private static int _donor_expiry_month;
private static int _donor_expiry_year;
private static int _donor_amt;
private static int _donor_rows;
private static object _donor_id;
public int Donor_Amt
{
get { return _donor_amt; }
set { _donor_amt = value; }
}
public Int64 DonorCredit
{
get { return _donor_credit_card; }
set { _donor_credit_card = value; }
}
public int DonorCCV
{
get { return _donor_ccv; }
set { _donor_ccv = value; }
}
public int DonorExpMonth
{
get { return _donor_expiry_month; }
set { _donor_expiry_month = value; }
}
public int DonorExpYear
{
get { return _donor_expiry_year; }
set { _donor_expiry_year = value; }
}
public int DRows
{
get { return _donor_rows; }
set { _donor_rows = value; }
}
public object DonorId
{
get { return _donor_id; }
set { _donor_id = value; }
}
}
}
What I have tried:
-I've tried to rearrange where my new instance is created, I've triple checked all my other code, and have finally realized that there is something here that is wrong.
-If I create a select statement and include a WHERE clause, it works perfectly and returns only a single row that I need.
-I've removed some other columns I'm trying to retrieve to make this code a little cleaner, but when I run this select statement in SQL developer, it works perfectly to return 3 distinct rows.
-I'm stumped. Stack Overflow is stumped (or it's too long winded of a question).
-Let me know if there's any other information you need.