Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 165
  • Last Modified:

Search Function

I need to be able to search a column of numbers or a column of text values, for a specific number or name in an Access database using a VB form (using a text box to receive the input) and a Search button event handler to launch the search.  I do not know how to do this, any help would be appreciated.  Also, In addition to finding a specific number or name value, once the value is found I need to populate the text boxes that will store the rest of the data from the record.
0
bfrancisco
Asked:
bfrancisco
1 Solution
 
NBrownohCommented:
if you use an ADODC control to connect to the database you can use SQL statements to query the databse.
SELECT * FROM YourTable WHERE ColumnName = 'SearchVal'
that is one possible sql statement to grab search specific results
0
 
GrahamSkanCommented:
To use the query:

Adodc1.RecordSource = "Select ...
Adodc1.Refresh

To Populate the text boxes, set (in the properties window), their DataSource as the data control (Adodc1), and each one's Datafield to the field name desired.
0
 
bfranciscoAuthor Commented:
Here's my code from the search event handler.  When I enter a number that I know exists in the database, I launch the event handler and it returns with break:

Private Sub btnCmdSrch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCmdSrch.Click
        Dim sql As String
        sql = "SELECT * FROM PRODUCTS WHERE PROD_ID=00001"
        MsgBox(sql)
        Dim btnSrch_cmd As New OleDb.OleDbCommand(sql, Conn)
        btnSrch_cmd.ExecuteNonQuery() ("This is the line my code breaks on")
End Sub

Thanks for taking a look at this.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
GrahamSkanCommented:
I'm a bit lost here.
Are you using using VB or Access and which versions.
I only know up to VB6 and Access 2000 & have never had to use an OleDB object.
0
 
fsaimsCommented:
Add this command line in your code: -

 Dim sql As String
        sql = "SELECT * FROM PRODUCTS WHERE PROD_ID=00001"
        MsgBox(sql)
        Dim btnSrch_cmd As New OleDb.OleDbCommand(sql, Conn)
'Add this line
Conn.Open()
        btnSrch_cmd.ExecuteNonQuery() ("This is the line my code breaks on")
Conn.Close()
0
 
bfranciscoAuthor Commented:
GrahamSkan,
I'm using Vb.Net to create an application.  The application connects to an Access 2000 type database.  The search function will be run from the application, i.e., I trying use a Search command button event handler in a Vb which executes code and an SQL statement which searches through a column in an Access database looking for a specific value.  Once the search function finds the specific value, I want a whole row of data retuned to the Vb form to populate text boxes.

Also, fsaims, I tried your solution but it doesn't work; the code breaks for an unhandled exception error at the Conn.Open() statement.

Thanks for attempting to help.  If each of you can be of further assistance that would be great.  I went out and bought a couple of books today, a Microsoft ADO.NET book by David Sceppa and a VB.NET book by Brian Siler and Jeff Spotts.  I'm hoping to find my solution therein.  Cheers!
0
 
GrahamSkanCommented:
Thanks for the feedback and good luck
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now