.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Forum >> ASP.Net >> Post New QuestionBookmark and Share Subscribe to Forum

Query against datatable using c#

Posted By: Deco     Posted Date: October 26, 2010    Points:2   Category :ASP.Net
Can anyone get me the code to query against the data table.

assume that my DataTable in a dataset has customer details from all around the world, i would like to get the specific region from the data table.

Responses
Author: Syed Shakeer Hussain             
Posted Date: October 26, 2010     Points: 5   

Hi,
try with the following code
string filter = "region = 'India'";
DataRow[] drr = dt1.Select(filter ) ;


DataTable dt2 = new DataTable ();


dt2 = drr.CopyToDataTable();


grid.DataSource= dt2;


Author: Santosh             
Posted Date: October 26, 2010     Points: 5   

Dim PrimaryDataTable as new datatble = ds.table(0) ' ds is ur dataset name
dim FilteredDataTable as new datatable
dim _SearchColumnName as string = 'region'
For Each row As DataRow In _PrimaryDataTable.Rows
If Not IsDBNull(row(_SearchColumnName)) Then
If row(SearchColumnName).ToString().Trim.ToUpper.StartsWith('India') Then
rowSearchResult = _FilteredDataTable.NewRow()
rowSearchResult.ItemArray = row.ItemArray
_FilteredDataTable.Rows.Add(rowSearchResult)
End If
End If
Next

Return _FilteredDataTable


Hope this will help u

Regards
Santosh

Author: Asha.MP             
Posted Date: October 26, 2010     Points: 5   

Hi..

You can use LINQ for the datatable to get the required result

selDt = From detail In table1.AsEnumerable Where detail.Field(Of String)("Place") = "Bangalore" Select detail
datatable selectedDt = selDt.CopyToDataTable


In the above query
detail is the alias name and table1 is the datatable name from which yu have to filter the data and "Place" represents the Column name and "Bangalore" represents the Value to be compare.

selectedDt is the datatable contains the result of the query
Hope this will help you...

Thanks and Regards,
Asha.mp


Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend