I would be grateful if anyone could let me know of an easy way of searching multiple tables for information.

I would like to display any found results in a grid alowing the user to choose the correct one and have this disply in the main form.

If this easy to do? I know it will need joins etc., but these are new to me.

Thanking you in advance.

Recommended Answers

All 18 Replies

Member Avatar for iamthwee

If you are looking to pull out just one value (field) then this is simple enough. But databases are not like that, they're linked to different tables. How they are linked will depend on how easy it is to get the correct data out.

The tables are one table linked to three or four others (each of these are not link to each other)

Does this help?

Member Avatar for iamthwee

Is it possible to show us a schematic of your tables, how they are linked and what are the primary keys etc.

Please find the information below, thanks for you help.

Member Avatar for iamthwee

I can barely read that text can you post a picture where all the text is big and clear to read. Thanks.

Hi,

what u actually want..? Search all the fields of all the tables for any one Specific condition...?

-Vee

Vee, well put that is what I want.

I know this seems strange, but the old DB (propitiatory) can do this and they want to keep that functionality.

Hi,

What is the Database u r using..? Access..?

-Vee

QVeen72, I am using SQL Server Express edition at the moment, but do have full standard version available if needed.

hi,

In Total how many tables do u need to do search operation..?
If Many Tables, and many recs in each table, then this will be a huge Overhead on the database.
But if u need to do it compulsorily, Write a Stroredprocedure which accepts Search String. And Checks each table and returns Table Name/id/fieldname if found..

Regards
Veena

Hi,

u can check the Storedprocedure here
It Checks and Replaces, u can modify it to Check and Return back...

Regards
Veena

There are five tables, and I imaging in total about 5,000 records (once completed).

Thank you for the link, that looks great.

I have had a chance to test the code and it works well, not all I have to do is to work out how to get the result into a format that will be useful to me.

Time to try and put my thinking cap on.

Hi,

Just Get the Stored procedure to output these parameters, If the Search is Matched..:

TableName, FieldName, FieldValue, ID of the Matched record.

If user selects some thing from the List, the Next drill down would be easy since u know Table name, field name and ID of the Table...

REgards
Veena

Thanks Veena.

This will enable everything to work.

Thanks once again.

Michael

I have been working on this for a while.

Using the stored Procedure from the link QVeen72 provided I have been able to get the search results I want with in SQL.

My problem is getting this to display in vb.net in a data grid.

Can anyone offer some help as to where to look for a solution.

The code I am using at the moment is:

Dim cs As String = "Data Source=.\SQLEXPRESS;Initial Catalog=Database;Integrated Security=True"
Using con As New System.Data.SqlClient.SqlConnection(cs)
con.Open()
Dim cmd As New System.Data.SqlClient.SqlCommand()
cmd.Connection = con
cmd.CommandType = CommandType.StoredProcedure
cmd.CommandText = "SearchAllTables"
cmd.Parameters.Add("@SearchStr", SqlDbType.NVarChar, 12)
cmd.Parameters("@SearchStr").Value = TextBox1.Text
Using reader As System.Data.SqlClient.SqlDataReader = cmd.ExecuteReader()
DataGridView1.DataSource = reader
End Using

The information I have see says that the last line should add: DataGridView1.DataBind, but I do no seem to have this as an option and it does not work if there is.

I have managed to get everything solved.

Thank you for your help.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.