?
Solved

Super easy points: Searching a dataset...

Posted on 2005-03-24
9
Medium Priority
?
209 Views
Last Modified: 2010-04-16
What is the proper way to search a dataset and bind the data that was found to a datagrid?

I was thinking something along the lines of...

DataRow[] rows = dataSet.Tables[0].Search("Address = ' " + txtAddress.Text + " ' ");
and then binding the returned rows to the datagrid, but no matter what I do it doesn't work.

What is the best way of doing something like this?
0
Comment
Question by:PoeticAudio
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 6

Author Comment

by:PoeticAudio
ID: 13626381
OOPS!!!!


that was supposed to be

DataRow[] rows = dataSet.Tables[0].Select("Address = ' " + txtAddress.Text + " ' ");


(I had Tables[0].Search in the original post)


0
 
LVL 6

Expert Comment

by:melodiesoflife
ID: 13627253

DataView myDataView = new DataView();
myDataView.Table = dataSet.Tables[0];
myDataView.RowFilter = "Address = ' " + txtAddress.Text + " ' ";

Good luck
0
 
LVL 16

Expert Comment

by:Walter Ritzel
ID: 13627908
DataView myDataView = new DataView(dataSet.Tables[0],"Address = ' " + txtAddress.Text + " ' ","",System.Data.DataViewRowState.OriginalRows );
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 6

Author Comment

by:PoeticAudio
ID: 13630669
ahh... the only thing that stinks about that, is if the cell has a single quote and you search for that record an error gets thrown.

ie:

if you search for peter's it yells at me saying invalid constant.

0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 200 total points
ID: 13631204
Replace 1 single quote with 2 single quotes:

txtAddress.Text.Replace("'", "''")

Bob
0
 
LVL 16

Expert Comment

by:Walter Ritzel
ID: 13633148
This error occurs due to the string concatenation. Bob is right, the replace will prevent the error.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses
Course of the Month11 days, 4 hours left to enroll

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question