0

HI all, I just want to ask how we can add more than 1 table in dataset or dataadapter through coding not through wizard.

2
Contributors
1
Reply
3
Views
9 Years
Discussion Span
Last Post by AmirBedair
0

Hi Gaurav,

chekc the next code to add datatables to dataset

//declare dataset and datatables
            DataSet ds = new DataSet("DS");
            DataTable dt1 = new DataTable("DT1");
            DataTable dt2 = new DataTable("DT2");

            // add columns by code
            dt1.Columns.Add("Col1", typeof(Int32));
            dt1.Columns.Add("Col2", typeof(string));
            dt1.Columns.Add("Col3", typeof(string));

            dt2.Columns.Add("Cl1", typeof(Int32));
            dt2.Columns.Add("Cl2", typeof(string));

            // add datatables to dataset 
            ds.Tables.Add(dt1);
            ds.Tables.Add(dt2);


            // to access tables by name or by no.
            // this to access table by name to get dt1
            DataTable dtTemp =  ds.Tables["DT1"];

            //this will return DT1
            DataTable dtTemp2 = ds.Tables[0];
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.