Convert Dataset to Datatable and Viceversa using asp.net


Sometimes we come across a Scenario we need to convert a Dataset to Datatable and Datatable to Dataset in our Code to meet our required Solution. So this Article will helps to those who convert dataset to datatable and datatable to Dataset.

Sometimes we come across a Scenario we need to convert a Dataset to Datatable
and Datatable to Dataset in our Code to meet our required Solution. So this Article will helps to those who convert dataset to datatable and datatable to dataset.

Lets see the Piece of Code how it works ...



DataTable dstset = new DataTable();
dstset = getDataTableFromExcel(path);
DataTable dataTable = dstset.AsEnumerable().Skip(startLimit).Take(EndLimit).CopyToDataTable();



To Convert datatable to dataset. You know it theoretically a Dataset is nothing but combination of many datatable(s) so what i will do here is i will take one instance of the Dataset and add many Datatable(s) in to it.



dataTable = dstset.AsEnumerable().Skip(startLimit).Take(EndLimit).CopyToDataTable();
dst = new DataSet();
dst.Tables.Add(dataTable);
swxml = new System.IO.StringWriter();
dstset.TableName = "SoverignPartInfo";
dstset.WriteXml(swxml);
if (startLimit >= 1350)
{

}
string strpartDetails = swxml.ToString();
InsertedOracleDatabase(strpartDetails);
startLimit = startLimit + EndLimit;




Here is the Real time You can see how i add that...

datasetdatabales


Attachments

Article by srirama
A Good advice from parent to a Child , Master to a Student , Scholar to an Ignorant is like a doctor prescribed pill it is bitter to take but when they take it will do all good for them --- Bhushan

Follow srirama or read 73 articles authored by srirama

Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: