CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2009
    Posts
    4

    Searches by no primary key fields

    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

    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!

  2. #2
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,284

    Re: Searches by no primary key fields

    Welcome to the forums!

    I'm old fashioned, and I'd suggest using the good old fashioned SELECT WHERE SQL statement, for example :
    Code:
    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!

  3. #3
    Join Date
    Apr 2009
    Posts
    4

    Re: Searches by no primary key fields

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured