Click here to Skip to main content
15,888,401 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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...
Posted

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. :)
 
Share this answer
 
Comments
ajithk444 11-Oct-12 1:28am    
i have my data in a dataset "ds" binded to the grid.

<pre lang="c#"> public DataTable getRowsByFilter()
{
List<string> Mylist = new List<string>();
Mylist=GetInvoiceNumber();
DataTable dt = new DataTable("InvoiceNumbers");
foreach (string InvNum in Mylist)
{
foreach (DataRow SrcDr in ds.Tables[0].Rows)
{
dt.Rows.Add(ds.Tables[0].Select("InvoiceNumber='" + InvNum + "'"));
}
}
return dt;
}</pre>


this is the code i have tried.but it's not woring. any changes should i do.?! pls help..
Hi Ajith,

Please try the below code snipet.

C#
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>
 
Share this answer
 
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

And your ID is:
C#
int[] id = new int []{ 1, 3, 5 };

So your query should be something like this:
C#
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



Hope it helped you.
---Amit
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900