abdujalil  chuliev

abdujalil chuliev

  • NA
  • 400
  • 41.3k

even and odd values

Sep 18 2015 4:53 AM
These methods give result, only if both Image_ID1 and Image_ID2 are not null.
If one of them or both of them are null, then it shows error.
Besides it returns only even values, odd values are skipped.
Example, Column Image_ID1=1,3,null and Image_ID2=2,4,6.
It has to show 5 values but it shows 4 values cause of that null value.
How can I solve these issues?

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 Image_ID1, Image_ID2 from register where students_ID='" + getStudents_ID() + "'AND Image_ID1 IS NOT NULL AND Image_ID2 IS NOT NULL";
MySqlCommand cmd = new MySqlCommand(query);
cmd.Connection = con;
MySqlDataReader reader = cmd.ExecuteReader();
foreach (DbDataRecord s in reader)
{
i.Add(s.GetInt32(0));
i.Add(s.GetInt32(1));
}
return i;
}

Answers (5)