它将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();
}
答案 0 :(得分:0)
更改
if (drow["approved"].Equals("yes"))
到
if (drow["approved"].ToString().StartsWith("yes"))