using (SqlConnection conn = new SqlConnection("Data Source=.;Initial Catalog=test;Integrated Security=True"))
{
DataSet ds=new DataSet();
string selectText="select * from tab_cJ";
SqlDataAdapter sda = new SqlDataAdapter(selectText, conn);
sda.Fill(ds);
DataTable oldDT = ds.Tables[0];
DataTable newDT = oldDT.Clone();
foreach (DataRow oldDR in oldDT.Rows)
{
if (int.Parse(oldDR["age"].ToString()) > 13)
{
DataRow newDR = newDT.NewRow();//新表创建新行
newDR.ItemArray = oldDR.ItemArray;//旧表结构行赋给新表结构行
newDT.ImportRow(oldDR);
}
}
GridView1.DataSource = newDT;
GridView1.DataBind();
}