Click here to Skip to main content
15,067,335 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Folks,

I do have a search string, and I need to display the words similar to that search string from a particular Oracle DataTable.

I am able to do that but since the search is through the entire
DataTable it's time consuming, thus creating a performance issue.
Please suggest how do I go for it...
Updated 2-Sep-10 5:52am
Dalek Dave 2-Sep-10 11:52am
Minor Edit for Grammar.

1 solution

If you are searching only in one field, just use standard SQL command:

SELECT myfield FROM mytable WHERE criteria=searchstring;

If you are searching on the whole row, try this:

using System.Data;
using System.Linq;

// this is for single result, would return null if no result
DataRow result = (from DataRow r in tableVariable.Rows
where string.Join(",", r.ItemArray).Contains(searchString)
select r).FirstOrDefault();

// and this is for many result
List<DataRow> results = (from DataRow r in tableVariable.Rows
where string.Join(",", r.ItemArray).Contains(searchString)
select r).ToList();

Haven't tried it though, but I think it is an fast and effective way (not time-consuming).
RoopikaS 3-Sep-10 2:37am
Hey Dalek,,
Thanks for your answer, But my concern was,
I am trying to search a string from table, I do know the Column name of the same,and am searching the user entered Search String in that particular Column


OracleConnection Oracon = new OracleConnection(sql);
OracleDataAdapter dataAdapter = new OracleDataAdapter("SELECT * FROM MY_TABLE", Oracon);
dt = new DataTable();
DataView dv1 = new DataView(dt);
foreach (DataRow row in dt.Select())
// Do something with columnValue

This is the way Im getting the values from Table and then I am carrying out
Search on it..

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