473,383 Members | 1,822 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Search DataSet for a string value

denny1824
I have a DataSet that is filled from a sql select statement that returns one table and most likely just a few rows.

I need a way to search the second column of the table in the DataSet to see if any of the rows match a specific string.

This is coded in C#.Net in a windows application.

Expand|Select|Wrap|Line Numbers
  1. DataSet ds = new DataSet();
  2. SqlCommand cmd = new SqlCommand(selectString, conn);
  3. SqlDataAdapter da = new SqlDataAdapter(cmd);
  4. da.Fill(ds);
  5.  
Thanks for any advice or direction,
denny1824
Feb 8 '10 #1

✓ answered by denny1824

I was able to come up with a solution.

Expand|Select|Wrap|Line Numbers
  1. foreach (DataRow row in ds.Tables[0].Rows)
  2.    {
  3.    if (row.ItemArray[1].ToString() == searchString)
  4.       {
  5.       blnFound = true;
  6.       }
  7.    }
  8.  

3 2438
tlhintoq
3,525 Expert 2GB
I'm not hugely experienced with this but...

Wouldn't it be more correct to do another query on the database with a more specific selectString?
Feb 8 '10 #2
The searching of the DataSet will be done in a loop, with a different string each iteration. I don't want to be hitting the database that many times when I already have the data I just need a way to verify if the string is in the DataSet.
Feb 9 '10 #3
I was able to come up with a solution.

Expand|Select|Wrap|Line Numbers
  1. foreach (DataRow row in ds.Tables[0].Rows)
  2.    {
  3.    if (row.ItemArray[1].ToString() == searchString)
  4.       {
  5.       blnFound = true;
  6.       }
  7.    }
  8.  
Feb 9 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Job Lot | last post by:
My DataGrid is bound to DataSet which contains relationship between two tables as follows: SqlHelper.FillDataset(strConn, CommandType.StoredProcedure, "spSelectClientApplicant", ds, New String()...
1
by: Matthew Curiale | last post by:
I am trying to create a search page for a database that will display in a repeater, using a stored procedure. The page_load is fine, and calls/displays all rows from the db just fine. When I input...
1
by: ratnakarp | last post by:
Hi, I have a search text box. The user enters the value in the text box and click on enter button. In code behind on button click i'm writing the code to get the values from the database and...
2
by: UJ | last post by:
I have a dataset that will have say 10000 records in it with the names of files that are used by the system. I then have a large directory of files that correspond to that list of files and want to...
1
by: Eric | last post by:
Hi: I have two files. I search pattern ":" from emails text file and save email contents into a database. Another search pattern " field is blank. Please try again.", vbExclamation + vbOKOnly...
5
by: samoore33 | last post by:
I use the code below to return rows matching the state in the theState variable. I want to know if it is possible to search through the DataRow that I am returning with the search. I understand...
0
by: | last post by:
I have a question about spawning and displaying subordinate list controls within a list control. I'm also interested in feedback about the design of my search application. Lots of code is at the...
0
by: rickbear | last post by:
Hi group... I am having big difficulties with dataset and xsd schemas. First I dedicate a specific schema to a dataset. Then I use an adapter to fill each table in the dataset. But the problem...
0
by: =?Utf-8?B?TGFzdGJ1aWxkZXJz?= | last post by:
Hi all, I have a weird problem which has been causing me a headache for the last two days. I have to dynamicly generate a schema in memory and load it into a dataset in memory to be returned...
0
by: Mark112 | last post by:
Hi I am attempting to restore the search feature that was created by an external company using the indexing service for our intranet. the intranet is located locally at each of our offices. The...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.