?
Solved

Super easy points: Searching a dataset...

Posted on 2005-03-24
9
Medium Priority
?
220 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
6 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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

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.

Question has a verified solution.

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

The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
SQL Database Recovery Software repairs the MDF & NDF Files, corrupted due to hardware related issues or software related errors. Provides preview of recovered database objects and allows saving in either MSSQL, CSV, HTML or XLS format. Ensures recov…

621 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