Ast*_*aar 2 c# asp.net datatable datarow
我正在尝试使用由MySqlDataAdapter填充的DataTable,其中包含博客条目的注释列表.由于某些原因,如果字段"anonymous"设置为"1",则username字段为空,应替换为指定的字符串.
我遇到的问题是,每当我尝试获取字段的值时,我会得到"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();
Run Code Online (Sandbox Code Playgroud)
该字段可能是一个"位"字段类型,它在ADO.NET中映射到布尔值
只需检查是真是假:
if ((bool)row["anonymous"])
...
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1485 次 |
| 最近记录: |