它将“approved”列的值返回为“yes \ 0 \ 0 \ 0 \ 0 \ 0 \ 0”而不是“yes”

时间:2016-08-19 10:29:01

标签: c#

它将approved列的值返回为"yes\0\0\0\0\0\0"而不是"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();
}

1 个答案:

答案 0 :(得分:0)

更改

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

if (drow["approved"].ToString().StartsWith("yes"))