Copy rows from one datatable to another datatable
-
DataSet ds = new DataSet(); DataTable dt = new DataTable("mytab"); DataColumn dc = new DataColumn("mycol", typeof(Int32)); dc.AutoIncrement=true; dt.Columns.Add(dc); ds.Tables.Add(dt); SqlDataAdapter da = new SqlDataAdapter("select * from authors",con); da.Fill(ds,"mytab"); dgrid.DataSource=ds.Tables["mytab"].DefaultView; dgrid.DataBind();
Now i want to select/filter some rows from the datatable "mytab" and copy that rows to other datatable say "mynewtab" and after that i want to insert rows from "mynewtab" to the database. I`ve used pubs database. I want only selected rows i.e (mycol <=2) from "mytab" and copy those rows to "mynewtab" and then insert rows from "mynewtab" to some other database table. Please help me. -
DataSet ds = new DataSet(); DataTable dt = new DataTable("mytab"); DataColumn dc = new DataColumn("mycol", typeof(Int32)); dc.AutoIncrement=true; dt.Columns.Add(dc); ds.Tables.Add(dt); SqlDataAdapter da = new SqlDataAdapter("select * from authors",con); da.Fill(ds,"mytab"); dgrid.DataSource=ds.Tables["mytab"].DefaultView; dgrid.DataBind();
Now i want to select/filter some rows from the datatable "mytab" and copy that rows to other datatable say "mynewtab" and after that i want to insert rows from "mynewtab" to the database. I`ve used pubs database. I want only selected rows i.e (mycol <=2) from "mytab" and copy those rows to "mynewtab" and then insert rows from "mynewtab" to some other database table. Please help me.