Visual Basic Code , VB.NET Code, VB Code
  Home   :  Code   :  Forums   :  Submit   :  Mailing List   :  About   :  Contact
A1VBCode Forums
Home      Members   Calendar   Who's On
Welcome Guest ( Login | Register )
      

Home » .NET Programming (VB 2010 or earlier) » C# » Find in Tables


Find in TablesExpand / Collapse
Author
Message
Posted 11/8/2011 4:41:12 AM
Forum Member

Forum MemberForum MemberForum MemberForum MemberForum MemberForum MemberForum MemberForum 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
Post #30888
Posted 3/7/2012 6:32:02 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum 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
Post #31264
« Prev Topic | Next Topic »


Reading This TopicExpand / Collapse
Active Users: 1 (1 guest, 0 members, 0 anonymous members)
No members currently viewing this topic.
Forum Moderators: Admin, Mod, Mark, Keithuk

PermissionsExpand / Collapse

All times are GMT -5:00, Time now is 2:27am