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
{
List
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;
}
Francis SusaimichaelPosted Sep 18, 2015, 6:34 AM
{
if (!reader.IsDBNull(reader.GetOrdinal("Image_ID1")))
i.Add(s.GetInt32(0));
else
i.Add(0); // if null means you can add what you want
if (!reader.IsDBNull(reader.GetOrdinal("Image_ID2")))
i.Add(s.GetInt32(1));
else
i.Add(0); // if null means you can add what you want
}
Francis SusaimichaelPosted Sep 18, 2015, 7:54 AM
abdujalil chulievPosted Sep 18, 2015, 6:51 AM
abdujalil chulievPosted Sep 18, 2015, 6:24 AM
Francis SusaimichaelPosted Sep 18, 2015, 6:06 AM
{
i.Add(s.GetInt32(0));
i.Add(s.GetInt32(1));
}