Super easy points: Searching a dataset...

Posted on 2005-03-24
Medium Priority
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?
Question by:PoeticAudio
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

Author Comment

ID: 13626381

that was supposed to be

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

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


Expert Comment

ID: 13627253

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

Good luck
LVL 16

Expert Comment

by:Walter Ritzel
ID: 13627908
DataView myDataView = new DataView(dataSet.Tables[0],"Address = ' " + txtAddress.Text + " ' ","",System.Data.DataViewRowState.OriginalRows );
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.


Author Comment

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.


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

LVL 96

Accepted Solution

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

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

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.

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