我试图使用一个由MySqlDataAdapter填充的数据表,其中包含一个博客条目的注释列表。出于某些原因,如果字段“anonymous”设置为“1”,则用户名字段为空,应替换为指定的字符串。
我遇到的问题是,每当我试图获取字段的值时,我要么得到“true”,要么得到“false”。我的代码如下所示:
DataTable modifiedComments = new DataTable();
// The function GetCommentsById() returns a MySqlDataAdapter with the result of the query
MySqlDataAdapter commentsContainer = Wb.Entry.GetCommentsById(imageId);
commentsContainer.Fill(modifiedComments);
commentsContainer.Dispose();
foreach (DataRow row in modifiedComments.Rows)
{
string status;
// This never returns true, so we always get into the else
if (row["anonymous"] == "1")
{
status = "You are anonymous";
}
else
{
status = "You are not anonymous";
}
}
viewImageCommentsRepeater.DataSource = modifiedComments;
viewImageCommentsRepeater.DataBind();