I have a database with two tables, one for login and another one for games bought. I created a session for login and now I'm having trouble displaying all the rows of this specific customer. I can view the table relationship from MS Access, but I don't know how to display them in labels.
Here's my coding:
OleDbDataReader myReader = null;
OleDbCommand cmd = new OleDbCommand("select * from new_table, games where new_table.MemberID='" + Session["New"] + "'", con);
myReader = cmd.ExecuteReader();
while (myReader.Read())
{
label_id.Text = (myReader["MemberID"].ToString()); //welcome user
}
OleDbDataReader myReader2 = null;
OleDbCommand cmd2 = new OleDbCommand("select * from new_table, games where '" + Session["New"] + "' = games.custID", con);
myReader2 = cmd2.ExecuteReader();
if (myReader2.HasRows)
{
DataTable dt = new DataTable();
dt.Load(myReader2);
label1.Text = dt.Rows[0]["gameTitle"].ToString();
label2.Text = "$" + Convert.ToDecimal(dt.Rows[0]["gamePrice"]).ToString("N2");
label3.Text = "$" + Convert.ToDecimal(dt.Rows[0]["gameDisc"]).ToString("N2");
label4.Text = dt.Rows[2]["gameTitle"].ToString();
label7.Text = dt.Rows[4]["gameTitle"].ToString();
}
My problem here is that if I set dt.Rows[3]
it shows error System.IndexOutOfRangeException: There is no row at position 3.
. I'm still a beginner in C# sorry if this was posted before. Sorry for my bad english, it is not my first language.
Try this query:
string query = "select * from (games
inner join new_table on games.custID = new_table.MemberID)
where new_table.MemberID = '" + Session["New"] + "'";
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.