从C#中的数据集中创建具有很少记录的数据集 [英] create dataset with few records from a dataset in c#

查看:94
本文介绍了从C#中的数据集中创建具有很少记录的数据集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数据集,该数据集包含50多个行,每个行都有一个唯一的ID,例如Invoivce#121,Invoivce#122等的InvoiceNumbers.
现在,我有了一个包含很少发票编号的字符串列表{Invoivce#121,Invoivce#122,Invoivce#124,Invoivce#125}.现在,我需要从数据集中检索清单中包含的发票编号的所有记录.帮帮我,..提前谢谢..

我希望将选定的记录保存到另一个数据集或datatable.pls帮助e在c#中为我的ASP.Net应用程序执行此操作...

i have a dataset which has over 50 rows each having a unique id as InvoiceNumbers like Invoivce#121,Invoivce#122 etc.
Now i have a string list which has few invoice numbers{Invoivce#121,Invoivce#122,Invoivce#124,Invoivce#125}.Now i need to retrieve all the records from the dataset with invoice number which i have in my list.Help me how to do this,..thanks in advance..

i want the selected records to be saved in another dataset or in a datatable.pls help e to do this in c# for my ASP.Net application...

推荐答案

维护两个数据库连接并以一种方式管理它们,即从一个数据库读取数据并将数据插入另一个数据库.如果您尝试过某些东西,请在此处显示.因此,我们可以对此发表评论. :)
Maintain two database connection and manage them in a way such that read data from one and insert data to the other. If you have tried something, please show it here. So we can comment on it. :)


嗨Ajith,

请尝试以下代码片段.

Hi Ajith,

Please try the below code snipet.

List<invoice> lstInvoice = new List<invoice>();
foreach(string str in strLst)
{
  for(int i=0;i<ds.table[0].rows.count;i++)>
  {
     if(str.Equals(ds.Table[0].Row[i]["InvoiceNumber"].ToString()))
     {
        Invoice inv = new Invoice();
        inv.InvoiceNumber = ds.Table[0].Row[i]["InvoiceNumber"].ToString(); //typecast same as inv.InvoiceNumber 
        lstInvoice.Add(inv);
     }
  }
}

After this you can save lstInvoice into the database or wherever you want.

Hope this will help you.

</invoice></invoice>



编写一个简单的linq查询以获取值.
我假设您的DataTable是:
Hi,
Write a simple linq query to get the values.
As I assumed your DataTable is:
1   Amit
2   Test1
3   Test2
4   Test3
5   test4


您的ID是:


And your ID is:

int[] id = new int []{ 1, 3, 5 };


所以您的查询应该是这样的:


So your query should be something like this:

var query = (from s in dt.AsEnumerable()
                        join p in id.AsEnumerable() on s.Field<int>("ID") 
                        equals Convert.ToInt32(p)
                        select s);
DataTable FilteredData = query.Count() > 0 ? query.CopyToDataTable() : null;</int>


因此,此查询将为您提供结果数据表,并且输出将如下所示:


So, this query will give you the resultant datatable and the output will be like this:

1   Amit
3   Test2
5   test4




希望对您有帮助.
--- Amit




Hope it helped you.
---Amit


这篇关于从C#中的数据集中创建具有很少记录的数据集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆