vincent vincent - 3 months ago 9
C# Question

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

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();
}

Answer

Change

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

to

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