Click here to Skip to main content
15,891,607 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear Friends,

I want to fetch data from dataset using like operator.

select * from TableName where Name like 'Sanjay%'

i want this type of query in dataset.
Please help me.
Posted

suppose ds is your dataset object and you want to query in 1st table i.e. at index 0. Then,
C#
DataView dv = ds.Tables[0].DefaultView;
dv.RowFilter = "[Name] LIKE 'Sanjay%'";

DataTable dtFiltered = dv.ToTable();

dtFiltered table will contain filtered rows.
 
Share this answer
 
v2
ds.table[0].Where(row => row.StringColumn.StartsWith("prefix"))

or

C#
ds.table[0].Where(p => p.UserName.StartsWith("Fr") && p.UserName.EndsWith("d") && p.UserName.Length == 4)



ds is your dataSet and table[0] is 0th table of dataset and StringColumn is Col name
 
Share this answer
 
v2
Hello mr Sanjay, use like this

SqlCommand cmd = new SqlCommand("select * from TableName where Name like '%" + TxtSearch.Text + "%' ", con);
 
Share this answer
 
ds.table[0].Where(p => p.UserName.Contain("Sanjay"));
 
Share this answer
 

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