Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jan 10th, 2008, 8:22 AM   #1
SydneyMcConnell
18 Year Old Programmer
 
Join Date: Jan 2008
Posts: 26
Rep Power: 0 SydneyMcConnell is on a distinguished road
Preforming a binary(SQL) search on a datagrid.

Hey, all. I have another problem that we're running into with our project.

We use data grids to handle the viewing of the main tables in our program, those tables being Employees, Invoices(Masters + Items), and Purchase Orders(Masters + items), and we're setting up a search function for them. We have one working. The only problem is that it's a serial search, running through the whole data grid to find what it's looking for. That's fine for small tables, but in a search like that, it becomes impractical when there are thousands of records like there would potentially be in an A/P system. There would be tremendous system slowdown, and I'm sure I'm not the only one who sees it as bad practice.

So, I'm wanting to preform a binary search, and I talked it over with my teacher. He said that I need to find a way to move the record pointer in the data grid without refreshing the data in the data grid, as the only thing I can think that's close to a binary search is preforming select queries based on the search parameters and eliminating all irrelevant data. I don't know if that's called anything different, but it's really the only way I know, and my teacher shot that down.

I guess what I'm asking is, is there any way to change the record pointer location of a data grid based on a SQL Select query, or is there a special SQL function for binary searches?

Any help is much appreciated.
Thanks. =]
__________________
Tier 2 Hardware Technician
Net Effects, LLC
Brunswick, Ohio
SydneyMcConnell is offline   Reply With Quote
Old Jan 10th, 2008, 11:33 AM   #2
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Posts: 1,722
Rep Power: 5 Sane is on a distinguished road
Re: Preforming a binary(SQL) search on a datagrid.

Will the parameter that's being searched for either be an exact match or not?

If it is a 'match or no match' situation, can you not perform a MySQL SELECT statement that searches for that particular row? Then retrieve the row number of that record.

Using the row number you can do whatever you need to your data grid, since the row number should correspond to the same row in your graphical interface's table. I'm assuming your data is being represented in the same order and size as your MySQL table. Or am I missing something?
Sane is offline   Reply With Quote
Old Jan 10th, 2008, 11:58 AM   #3
SydneyMcConnell
18 Year Old Programmer
 
Join Date: Jan 2008
Posts: 26
Rep Power: 0 SydneyMcConnell is on a distinguished road
Re: Preforming a binary(SQL) search on a datagrid.

It's going to be a dynamic search, in that it will change the results every time the key is pressed. The where clause is going to be a "LIKE", and not an "=" if that's what you mean.

I'm thinking of doing a Select statement, having that return a row, and then using that row to change the bindingcontext.location property of the form. I just don't know what I would reference to do that. I don't think I'd use the PK of the returned row to find it and then change the location... That seems extremely round-about. But is that how it would be done?

Also, if it helps any, we're using MSSQL.
__________________
Tier 2 Hardware Technician
Net Effects, LLC
Brunswick, Ohio
SydneyMcConnell is offline   Reply With Quote
Old Jan 10th, 2008, 12:24 PM   #4
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Posts: 1,722
Rep Power: 5 Sane is on a distinguished road
Re: Preforming a binary(SQL) search on a datagrid.

Quote:
...I'm thinking of doing a Select statement, having that return a row, and then using that row...
Quote:
...use the PK of the returned row to find it...
Same thing. The latter is more "round-about" if you want to look at it that way, but retrieving the row number of a query is still the exact same amount of work done by the application as retrieving the pk column in a query. So whichever you find easier from a coding standpoint...

So after you've done that, you then know the row number that matches the search query. Just reference that row number in the grid data and change its appearance. You can figure out how to do this by looking at the documentation for the GUI control you're using. This object will have methods that you can call, one of which should be able to modify the apperance of row #X. These methods will be listed along with their usage in their respective documentation.
Sane is offline   Reply With Quote
Old Jan 10th, 2008, 12:40 PM   #5
SydneyMcConnell
18 Year Old Programmer
 
Join Date: Jan 2008
Posts: 26
Rep Power: 0 SydneyMcConnell is on a distinguished road
Re: Preforming a binary(SQL) search on a datagrid.

I think we may have just found it.

When you assign a datasource to a data grid in .Net, it uses something called BindingContext to handle all interfacing with that datasource.

So, after speaking with a co-developer who is also on the project, and looking more in depth at how the search function works, we found that we could bind the Search textbox to the same Datasource as the data grid. By doing this, every time something is changed in the text box, it will change the location of the record pointer in the datasource, and the data grid will act accordingly to that change.

We are testing it now. If it works, I will paste the code for anyone who has a similar problem, complete with documentation.
__________________
Tier 2 Hardware Technician
Net Effects, LLC
Brunswick, Ohio
SydneyMcConnell is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to save all search engine results urls in a text file abojan ASP 0 Dec 27th, 2006 8:33 AM
Exporting a Datagrid to Excel problem Mortavitch Visual Basic .NET 0 Jul 14th, 2006 9:34 PM
Backup Search grimpirate C 3 Jul 3rd, 2006 7:49 PM
How can I disable particular rows in a datagrid? HappyTomato C# 2 Aug 25th, 2005 3:48 PM
An alternative to 'Windows Search'... SaturN Coder's Corner Lounge 9 Jul 24th, 2005 2:30 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 5:02 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC