Now I wan to retrieve a datatable value line by line. I had find a way to done it but I can't get the result I want. It only retrieve a line of record. Here is the code :
MySqlConnection connStr = new MySqlConnection();
connStr.ConnectionString = "Server = localhost; Database = healthlivin; Uid = root; Pwd = khei92;";
String searchPerson = "SELECT PersonIDB from contactFriend WHERE PersonID = @id";
MySqlCommand cmdSearch = new MySqlCommand(searchPerson, connStr);
connStr.Open();
cmdSearch.Parameters.AddWithValue("@id", "M000001");
MySqlDataReader dtrRead2 = cmdSearch.ExecuteReader();
dt.Load(dtrRead2);
dtrRead2.Close();
connStr.Close();
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
String s = (String)(DataBinder.Eval(e.Item.DataItem, "PersonID"));
String val = "";
for (int i = 0; i < dt.Rows.Count ; i++)
{
//val = dt.Rows[i]["PersonIDB"].ToString();
if (dt.Rows[i]["PersonIDB"].ToString().Equals(s))
e.Item.Visible = false;
else
e.Item.Visible = true;
}
EDIT
Page Load :
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
try
{
MySqlConnection connStr = new MySqlConnection();
connStr.ConnectionString = "Server = localhost; Database = healthlivin; Uid = root; Pwd = khei92;";
String searchOverall = "SELECT PersonID, PersonName, Email, Picture FROM Person";
MySqlCommand cmdSearch = new MySqlCommand(searchOverall, connStr);
connStr.Open();
MySqlDataReader dtrRead2 = cmdSearch.ExecuteReader();
friendRepeater.DataSource = dtrRead2;
friendRepeater.DataBind();
dtrRead2.Close();
dtrRead2 = null;
connStr.Close();
}
catch (Exception ex)
{
//MessageBox.Show(ex.ToString());
}
}
}
For the ItemDataBound :
protected void ItemDataBound(object sender, RepeaterItemEventArgs e)
{
//String personID = "";
DataTable dt = new DataTable();
try
{
MySqlConnection connStr = new MySqlConnection();
connStr.ConnectionString = "Server = localhost; Database = healthlivin; Uid = root; Pwd = khei92;";
String searchPerson = "SELECT PersonIDB from contactFriend WHERE PersonID = @id";
MySqlCommand cmdSearch = new MySqlCommand(searchPerson, connStr);
connStr.Open();
cmdSearch.Parameters.AddWithValue("@id", "M000001");
MySqlDataReader dtrRead2 = cmdSearch.ExecuteReader();
dt.Load(dtrRead2);
dtrRead2.Close();
connStr.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
String s = (String)(DataBinder.Eval(e.Item.DataItem, "PersonID"));
String val = "";
for (int i = 0, count = dt.Rows.Count; i < count ; i++)
{
//val = dt.Rows[i]["PersonIDB"].ToString();
//DataRow dr = dt.Rows[i];
if (dt.Rows[i]["PersonIDB"].ToString().Equals(s))
e.Item.Visible = false;
else
e.Item.Visible = true;
}
}
}