开发者

how to extract Datatable or DataSet from Linq Query or List

how to extract DataTable or DataSet from Linq Query or List. e.g I have linq query like this

MyDBpDataContext dcSp = new MyDBpDataContext(); dcSp.myProgrammSP().ToList();

I wrote an Sp which sends a Table as result and I have code which is already using DataTable So I w开发者_开发问答ant to convert this result in DataTable.


The result doesn't exist as a DataTable at any point, so if you want it as a DataTable, you have to create one and copy the data into it.

Example:

DataTable table = new DataTable("Items");
table.Columns.Add(new DataColumn("Id", typeof(Int32)));
table.Columns.Add(new DataColumn("Name", typeof(String)));
foreach (Item item in items) {
  DataRow row = table.NewRow();
  row["Id"] = item.Id;
  row["Name"] = item.Name;
  table.Rows.Add(row);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜