Click here to Skip to main content
15,935,248 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
for (int i = 0; i < 5; i++)
                DataTable tbl, tbl2;
                SqlDataAdapter adp = new SqlDataAdapter("Select ID, user ,Date, vehicle from booking where ID='100' and user='james'", con);
                tbl = new DataTable();

In tbl datatable the following data is generating every time. ie
ID user Date vehicle
100 james 02-02-2012 BMW

These above value will generate 5 times and i want to save all 5 records in another datatable ie tbl2.

INSERT INTO new_db.dbo.TableA
SELECT * FROM old_db.dbo.TableB
Share this answer
sahabiswarup 10-May-12 7:04am    
how to implement these above query?
sahabiswarup 10-May-12 7:08am    
In TableA there is only one record; Every time one row will add in TableB.
so that in TableB there are 5 records though there is only one record in TableA.
Unareshraju 10-May-12 7:14am    
here we should create a TableA which consist of five column after that you can use above command
sahabiswarup 10-May-12 7:28am    
i dont want to fix TableA row; every time TableA row value will be added on TableB new row.
I want to do like that.
SqlDataAdapter da1 = new SqlDataAdapter("Select booking_id,user_id,convert(char,date_of_travel,103) as date_of_travel, no_of_vehicle,vehicle from booking where user_id='" + Session["a"] + "' and booking_id='" + Session["key"].ToString() + "'", con);
        DataTable dt1 = new DataTable();
        if (dt1.Rows.Count > 0)
            int loop;
            DataTable tbl;
            DataTable tbl2 = new DataTable();
            DataSet ds = new DataSet();
            ds.Tables.Add(new DataTable());
            ds.Tables[0].Columns.Add("ID", typeof(int));
            ds.Tables[0].Columns.Add("Tour_Code", typeof(int));
            ds.Tables[0].Columns.Add("Tour_Date", typeof(string));
            //ds.Tables[0].Columns.Add("No_Of_Vehicle", typeof(int));
            ds.Tables[0].Columns.Add("Vehicle", typeof(string));
            tbl2 = ds.Tables[0].Clone();
            loop = Convert.ToInt32(dt1.Rows[0][3].ToString());
            for (int i = 0; i < loop; i++)
                SqlDataAdapter adp = new SqlDataAdapter("Select booking_id as ID,user_id as Tour_Code,convert(char,date_of_travel,103) as Tour_Date, vehicle as Vehicle from booking where user_id='" + Session["a"] + "' and booking_id='" + Session["key"].ToString() + "'", con);
                tbl = new DataTable();

                foreach (DataRow dr in tbl.Rows)
                    DataRow newRow = tbl2.NewRow();
                    newRow.ItemArray = dr.ItemArray;

            grdveh.DataSource = tbl2;
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900