6
Answers

foreach

Hello, the method given below is returning value only from the last rows
of Arrive_Img_ID and Leave_Img_ID. But four image ID exist in each column.
What should I do?

private string getImage_ID()
{
MySqlConnection con = new MySqlConnection(constr);
con.Open();
MySqlCommand cmd = new MySqlCommand("Select Arrive_Img_ID,Leave_Img_ID from register where Students_ID='" + getStudent_ID() + "'");
cmd.Connection = con;
MySqlDataReader reader = cmd.ExecuteReader();
string i = null;
while (reader.Read())
{
foreach (DbDataRecord s in reader)
{
i = reader["Arrive_Img_ID"].ToString();
i = reader["Leave_Img_ID"].ToString();
}
}
reader.Close();
return i;
}
Answers (6)