| | | Forum Member
       
Group: Forum Members Last Login: 4/29/2012 10:36:01 AM Posts: 61, Visits: 160 |
| Hi,
I have a function that returns all the database tables with the data items in it. Is it possible to search for a value in all tables and return the table name and the datarow that contains the value?
Thanks |
| | | | Forum Newbie
       
Group: Forum Members Last Login: 3/20/2012 9:59:13 PM Posts: 7, Visits: 5 |
| Hello Shers,
You can set a list of all tables and make a loop to search in them one by one.
Here are some tips for doing so, If it doesn't help, Let me know.
- Here you can get the names of all tables in a DataTable
DataTable t = _conn.GetSchema("Tables");
- Then declare a DataTable DT and fill it with each table, one by one and search in each as follows:
-----------------------------------------------------------------------------
String X = ... ; //Where x= the compared value you're searching for.
DataTable DT = new DataTable();
// fill the datatable with data
DT = [your function to get the data]
//Now here's how you search in each record in the DataTable
for (int i = 0; i < DT.Rows.Count; i++)
{
// DT.Rows[i] Where 'i' is the vertical position of the counter in the DT record set
// .ToString() is written because DR.Rows[][] returns an object not a string.
if(DT.Rows["i"]["ColumnName"].ToString() == X)
{
found.
}
}
--------------------------------------------------------------------------------------
That was a pseudocode like. If you cant implement the previous code, please send me the solution file and Ill help you.
Regards.
Amr Mohallel
University of Sunderland
Faculty of Applied Sciences - Applied Business Computing |
| |
|
|