views:

98

answers:

1

I'm trying to use a DataTable, filled by a MySqlDataAdapter, which contains a list of comments for a blog entry. For some reasons, if the field "anonymous" is set to "1", the username field is empty and should be replaced with a specified string.

The problem I have is that whenever I try to get the value of the field, I get either "true" or "false". My code looks like this:

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();
+4  A: 

The field is probably a "bit" field type, which maps to Boolean in ADO.NET

Simply check for true or false:

if ((bool)row["anonymous"])
   ...
Philippe Leybaert