Click here to Skip to main content
15,893,161 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
There is only a drop down list with student ID and a gridview with students' images in my web page.
If I select a student GridView has to show all the images of the selected student.
Problem is when I select a student my gridview is skipping first two values.
I mean if there are 6 images gridview shows only 4 images.
Here is my code:

C#
private void BindGrid()
    {
        MySqlConnection con = new MySqlConnection(constr);
        MySqlCommand cmd = new MySqlCommand("SELECT * FROM images where Image_ID in (" + String.Join(",", getImage_ID()) + ")", con);
        MySqlDataAdapter da = new MySqlDataAdapter(cmd);
        DataTable dt = new DataTable();
        da.Fill(dt);
        gvImages.DataSource = dt;
        gvImages.DataBind();
    }
    private List<int> getImage_ID()
    {
        List<int> i = new List<int>();
        MySqlConnection con = new MySqlConnection(constr);
        con.Open();
        string query = "Select Come_Image_ID1, Leave_Image_ID from register where Students_ID='" + getStudents_ID() + "' AND Come_Image_ID IS NOT NULL AND Leave_Image_ID IS NOT NULL"; 
        MySqlCommand cmd = new MySqlCommand(query);
        cmd.Connection = con;
        MySqlDataReader reader = cmd.ExecuteReader();
        while (reader.Read())
        {
            foreach (DbDataRecord s in reader)
            {
                i.Add(s.GetInt32(0));
                i.Add(s.GetInt32(1));
            }
        }
        reader.Close();
        return i;
    }


What is the best coding practice for this issue?
Examples would be nice.
Posted
Updated 16-Sep-15 19:59pm
v2

1 solution

try with below
C#
while (reader.Read())
{
   reader.Add(s.GetInt32(0));
   reader.Add(s.GetInt32(1));
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900