Please help me

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • hussaini
    New Member
    • Dec 2006
    • 24

    Please help me

    Hello buddies im new in visual basic so please tell me i have connected a database sql server with VB6 i want to know what is code of to search data like if im searching a name just like James in text field there record will searched so what is the code of it and same like in datagrid please help me
  • willakawill
    Top Contributor
    • Oct 2006
    • 1646

    #2
    Originally posted by hussaini
    Hello buddies im new in visual basic so please tell me i have connected a database sql server with VB6 i want to know what is code of to search data like if im searching a name just like James in text field there record will searched so what is the code of it and same like in datagrid please help me
    Hi. First you will need to open a connection to sql server with a connection object:

    Code:
    Dim cn As ADODB.Connection
    Set cn = New ADODB.Connection
    
    With cn
            .Provider = "SQLOLEDB"
            .Properties("Data Source") = "name of your sql server"
            .Properties("User ID") = "your user id"
            .Properties("Password") = "your password"
            .Open
            .DefaultDatabase = "your database name"
    End With
    You will then need a recordset object to return the rows you are searchng for.

    Code:
    Dim rs As ADODB.Recordset
    Set rs = New ADODB.Recordset
    
    With rs
             .ActiveConnection = cn
             .CursorType = adOpenStatic
             .CursorLocation = adUseClient
             .LockType = adLockOptimistic
    End With
    Then you construct an sql statement for your search and use that as the source for your recordset

    Code:
    Dim stSQL As String
    
    stSQL = "SELECT * FROM [Your Database Name] WHERE [Your Field Name] = '" & YourSearchCriteria & "'"
    
    rs.Source = stSQL
    rs.Open
    Good luck

    Comment

    • hussaini
      New Member
      • Dec 2006
      • 24

      #3
      Originally posted by willakawill
      Hi. First you will need to open a connection to sql server with a connection object:

      Code:
      Dim cn As ADODB.Connection
      Set cn = New ADODB.Connection
      
      With cn
              .Provider = "SQLOLEDB"
              .Properties("Data Source") = "name of your sql server"
              .Properties("User ID") = "your user id"
              .Properties("Password") = "your password"
              .Open
              .DefaultDatabase = "your database name"
      End With
      You will then need a recordset object to return the rows you are searchng for.

      Code:
      Dim rs As ADODB.Recordset
      Set rs = New ADODB.Recordset
      
      With rs
               .ActiveConnection = cn
               .CursorType = adOpenStatic
               .CursorLocation = adUseClient
               .LockType = adLockOptimistic
      End With
      Then you construct an sql statement for your search and use that as the source for your recordset

      Code:
      Dim stSQL As String
      
      stSQL = "SELECT * FROM [Your Database Name] WHERE [Your Field Name] = '" & YourSearchCriteria & "'"
      
      rs.Source = stSQL
      rs.Open
      Good luck
      well i dont understand ..... 1st of i have make connection then where is search code

      Comment

      • sashi
        Recognized Expert Top Contributor
        • Jun 2006
        • 1749

        #4
        Originally posted by hussaini
        well i dont understand ..... 1st of i have make connection then where is search code
        Hi there,

        What do you mean by you don't understand? Isn't the below code segment looks like "search code" that you have been looking for? Please take some time to learn things on your own too, here at TheScripts we help people to solve their coding problem & not providing full working application as per their need. Good luck & Take care.

        Code:
        Dim stSQL As String
        
        stSQL = "SELECT * FROM [Your Table Name] WHERE [Your Field Name] = '" & YourSearchCriteria & "'"
        
        rs.Source = stSQL
        rs.Open

        Comment

        • hussaini
          New Member
          • Dec 2006
          • 24

          #5
          ok would u like to tell me where i put these codes please tell me breif me

          Comment

          • hussaini
            New Member
            • Dec 2006
            • 24

            #6
            Ok dear sashi will u tell me urs yahoo id where ever u chat please tell me yaar

            Comment

            • willakawill
              Top Contributor
              • Oct 2006
              • 1646

              #7
              You don't have a chance at getting this to work with your approach. There is far too much to learn. There are, however, plenty of pundits who scroll through these questions looking for opportunities to show how much they know so you may be lucky and someone will complete your project for you.

              I recommend that you get a book and use the above code to assist you in learning what you need to learn.

              Good luck

              Comment

              • sashi
                Recognized Expert Top Contributor
                • Jun 2006
                • 1749

                #8
                Originally posted by hussaini
                Ok dear sashi will u tell me urs yahoo id where ever u chat please tell me yaar
                Hi there,

                The answer will be NO & NOTHING BUT NO.

                Comment

                Working...