Skip to content
Loading
  • Amit Gupta
    0
    DataSet is nothing but a collection of datatable. If you don't have to work more than 1 table then make the return type of the function as DataTable. In your case you can try new DataSet().Add(dtdatas);
    0
  • Amit Kumar
    0
    Hi, Use the below code it is working properly.
     
    1. public DataSet getDataSet()  
    2. {  
    3. //Create a new Dataset for return  
    4.   DataSet ds = new DataSet();  
    5.   
    6. DataTable dtresults = new DataTable();  
    7. dtresults .Columns.Add("Id");  
    8. dtresults .Columns.Add("Name");  
    9. dtresults .Columns.Add("Email");  
    10.   
    11. //Insert record in this table  
    12. dtresults.Rows.Add("1", "John", "[email protected]");        
    13. dtresults.Rows.Add("1", "Devid", "[email protected]");        
    14.      
    15. //Creating another DataTable to copy  
    16. DataTable dtdatas = dtresults.Copy();  
    17. ds.Tables.Add(dtdatas).  
    18.   
    19. return ds;  
    20.     }  
     
    0
  • Ranjit Powar
    0
    What is the return type of function?
    0
  • Mageshwaran R
    0
    Hi,
    Please refer the below link, it might helps you
    http://getcodesnippet.com/2013/06/20/how-to-add-datatable-to-dataset-in-c/ 
    0