Click to See Complete Forum and Search --> : Searches by no primary key fields


fsebastiao27
April 23rd, 2009, 04:02 AM
First of all, ive been reading this forums and it already helped me a lot with my application, im new to visual studio and im currently developing an aplication for my school project in vs 2008.

Im using a simple access database with only 2 tables and I creadted a form with a datagrid to show all data inside the tables, and now i want to create search buttons for each field of the table . like, "seach by Name", Seach by date" etc... i tried to use the simple code


Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim cod As String
cod = InputBox("Type the Id to search: ", "Search By ID")
If cod <> " " Then
Dim reg1 As distritos1('dataset).distritoRow = Distritos11.distrito.FindByid_distrito(Convert.ToInt32(cod))

If regi Is Nothing Then
MsgBox("Distrito not Found!!!")
Else
MsgBox(" distrito:" & registo.distrito_name)
End If
Else
MsgBox("Wrong Id!! ", MsgBoxStyle.Exclamation, "Search By Id")
End If
End Sub


My biggest problem now is that this code works very well to search by id (which is my table primary key), but now i want to search by other fields and this code only allows to search by primary key!
Is there any way to use something similar to this code to search by other fields?

Thanks for reading and i hope i can get help!

HanneSThEGreaT
April 23rd, 2009, 05:29 AM
Welcome to the forums! :wave:

I'm old fashioned, and I'd suggest using the good old fashioned SELECT WHERE SQL statement, for example :
SELECT * FROM Districts WHERE ClientName = 'Hannes'

A statement like the above would find all records where the ClientName's field contains Hannes.

I sincerely hope my post was helpful :)

PS, thank you so much for using CODE tags on your first post! :)

fsebastiao27
April 23rd, 2009, 05:41 AM
Thank you for your reply, i know a litle bit about SQL but now that i moved to visual studio, how do i apply that in the button1 command? sory but im really noob in .net