0

it returns the value of approved column as "yes\0\0\0\0\0\0" instead of "yes"

public void getapproved()
{
    SqlDataAdapter da = new SqlDataAdapter("select * from owner_addproperties", con);
    DataSet ds = new DataSet();
    da.Fill(ds);
    DataTable dtoriginaltable =ds.Tables[0];

    DataTable dtfinaltable = new DataTable();
    foreach (DataColumn dc in dtoriginaltable.Columns)
    {
        dtfinaltable.Columns.Add(dc.ColumnName);
    }

    foreach (DataColumn dc in dtfinaltable.Columns)
    {
        if (dc.ColumnName == "approved")
            dc.DataType = System.Type.GetType("System.Boolean");
    }
    foreach (DataRow drow in dtoriginaltable.Rows)
    {
        if (drow["approved"].Equals("yes"))
            drow["approved"] = true;
        else
            drow["approved"] = false;

        dtfinaltable.Rows.Add(drow.ItemArray);
    }

    gvadmin_owner_view.DataSource = dtfinaltable;
    gvadmin_owner_view.DataBind();
}
Gilad Green
  • 36,708
  • 7
  • 61
  • 95
vincent
  • 3
  • 2
  • 1
    You should ask yourself how those \0 are ended in your tables first and what you can do to avoid them. – Steve Aug 19 '16 at 10:40

1 Answers1

0

Change

if (drow["approved"].Equals("yes"))

to

if (drow["approved"].ToString().StartsWith("yes"))
Neil
  • 641
  • 1
  • 7
  • 21