Visual Basic Code , VB.NET Code, VB Code
  Home   :  Code   :  Forums   :  Submit   :  Mailing List   :  About   :  Contact


Find in Tables


Find in Tables

Author
Message
shers
shers
Forum God
Forum God (16K reputation)Forum God (16K reputation)Forum God (16K reputation)Forum God (16K reputation)Forum God (16K reputation)Forum God (16K reputation)Forum God (16K reputation)Forum God (16K reputation)Forum God (16K reputation)

Group: Forum Members
Posts: 66, Visits: 170
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
AmrMohallel
AmrMohallel
Forum God
Forum God (3.4K reputation)Forum God (3.4K reputation)Forum God (3.4K reputation)Forum God (3.4K reputation)Forum God (3.4K reputation)Forum God (3.4K reputation)Forum God (3.4K reputation)Forum God (3.4K reputation)Forum God (3.4K reputation)

Group: Forum Members
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
GO


Similar Topics


Reading This Topic


Login
Existing Account
Email Address:


Password:


Social Logins

Select a Forum....

















A1VBCode Forums


Search