Creating Datasets on the Fly

         //Create a DataSet
        DataSet Ds = new DataSet();
        //====================================
        //Create a DataTable
        //——————————————————-        
        DataTable Dt = new DataTable(“LabelsDt”);  
        //Add columns to it
        //——————————————————-        
        Dt.Columns.Add(“IsDrawn”);       
        Dt.Columns.Add(“id”);       
        Dt.Columns.Add(“AccessionNumber”);       
        Dt.Columns.Add(“FirstName”);       
        Dt.Columns.Add(“Initials”);       
        Dt.Columns.Add(“Sample”);       
        Dt.Columns.Add(“Image”);
        //====================================
        //Add DataTable (created) to DataSet
        //——————————————————-         
        Ds.Tables.Add(Dt);   
        //====================================
        //Add as many as rows as you want
J
        //Add DataRow for this DataTable and add it to DataSet’s Table[“LabelsDt”]
        //——————————————————-                  
        //Create DataRow              
        DataRow Dr = Ds.Tables[“LabelsDt”].NewRow();                    
        //Assign Values to DataRow cells                
        Dr[“IsDrawn”] = row.Cells.FromKey(“IsDrawn”).Value.ToString();               
        Dr[“id”] = row.Cells.FromKey(“id”).Value.ToString();               
        Dr[“AccessionNumber”] = row.Cells.FromKey(“AccessionNumber”).Value.ToString();               
        Dr[“FirstName”] = row.Cells.FromKey(“FirstName”).Value.ToString();               
        Dr[“Initials”] = row.Cells.FromKey(“Initials”).Value.ToString();               
        Dr[“Sample”] = row.Cells.FromKey(“Sample”).Value.ToString();               
        Dr[“Image”] = GenerateBarCode_DSBarCode(row.Cells.FromKey(“AccessionNumber”).Value.ToString());
        Ds.Tables[“LabelsDt”].Rows.Add(Dr); 
        //======================================

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: