2009-07-12 24 views
2

我試圖使用一個DataTable,由一個MySqlDataAdapter填充,它包含一個博客條目的評論列表。由於某些原因,如果字段「anonymous」設置爲「1」,則用戶名字段爲空,應該用指定的字符串替換。爲什麼我的DataTable總是返回「true/false」,但從來沒有一個字符串?

我遇到的問題是,每當我嘗試獲取字段的值時,我都會得到「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(); 

回答

5

領域可能是一個 「位」 字段類型,其映射在ADO.NET

爲Boolean簡單檢查true或false:

if ((bool)row["anonymous"]) 
    ... 
相關問題