Results 1 to 14 of 14

Thread: [RESOLVED] Search From The Database

  1. #1

    Thread Starter
    Frenzied Member met0555's Avatar
    Join Date
    Jul 2006
    Posts
    1,385

    Resolved [RESOLVED] Search From The Database

    Hi, I'm trying to make a program that will identify any file extension but I'm blocked here, I made the database with MS Access 2003 in 2000 format but then when the identify button is clicked i wasn't able to make it search from the database and show the result, can someone give me some help to make it work?

    thanks

  2. #2
    Frenzied Member
    Join Date
    Jul 2007
    Posts
    1,306

    Re: Search From The Database

    ok, I ll tell you, my crystal ball is out of order today, could please post your code?


    ps: dont get angry, just kiddin
    IIF(Post.Rate > 0 , , )

  3. #3

    Thread Starter
    Frenzied Member met0555's Avatar
    Join Date
    Jul 2006
    Posts
    1,385

    Re: Search From The Database

    i didn't write any code, normally i use this code on vb.net but now on vb6 i don't know where to start.
    vb Code:
    1. Private Sub butOk_Click(ByValsender As System.Object, ByVal e As System.EventArgs) Handles but_ok.Click
    2.     Dim strConnection As String = "Data Source=your SQL data source;Initial Catalog=your database; Integrated Security=True"
    3.     Dim cn As SqlClient.SqlConnection = New SqlClient.SqlConnection(strConnection)
    4.     Dim ds As New DataSet
    5.     Dim strSelect As String
    6.     'strSelect As String
    7.     strSelect = "SELECT * FROM " & YourTable & " WHERE [Search Field] = '" & Me.txtName.Text & "'"
    8.     Dim dscmd As New SqlClient.SqlDataAdapter(strSelect, cn)
    9.     dscmd.Fill(ds, "your table")
    10.     Me.Datagrid1.DataSource = ds
    11.     Me.Datagrid1.DataMember = "your table"
    12.     Dim con As Integer
    13.     con = Me.BindingContext(ds, "your table").Count
    14.     If con = 0 Then
    15.     MessageBox.Show("Recourd could not be found")
    16.     End If
    17.     End Sub

  4. #4
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: Search From The Database

    Quote Originally Posted by met0555
    . . . I'm trying to make a program that will identify any file extension but I'm blocked here, . . .
    What does this statment mean???

    Additionally, the code you posted is VB.Net not VB6.
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


  5. #5
    Frenzied Member
    Join Date
    Jul 2007
    Posts
    1,306

    Re: Search From The Database

    Oh. I m sorry , I dont know vb.net. but in vb6 you can use a ADO connection and recordset to get data. I ll put some code.

    to make a connection
    Code:
        Public dbcon As adodb.Connection
        Set dbcon = New adodb.Connection
        dbcon.CursorLocation = adUseClient
        dbcon.Open "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\ControlList.mdb;"
    to retrive data from your table and show in a data grid,

    Code:
    Private Sub datagrid_load()
        DataGrid1.Visible = True
        Dim op_grid_rs As New adodb.Recordset
        Dim strsql As String
        
        
        op_grid_rs.CursorLocation = adUseClient
        
           strsql = " SELECT Control_UserLevel.*,  Controls.ContainerID " & _
                 " FROM Controls INNER JOIN Control_UserLevel ON Controls.ControlName = Control_UserLevel.ControlName " & _
                 " ORDER BY Controls.ContainerID"
                 
        op_grid_rs.Open strsql, dbcon, adOpenStatic, adLockOptimistic
        op_grid_rs.Sort = "UserLevel"
        
        Set DataGrid1.DataSource = op_grid_rs
        
        
    End Sub
    Hope this helps.
    IIF(Post.Rate > 0 , , )

  6. #6
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: Search From The Database

    Take a look at this LINK
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


  7. #7

    Thread Starter
    Frenzied Member met0555's Avatar
    Join Date
    Jul 2006
    Posts
    1,385

    Re: Search From The Database

    Hi, i've tried your code like this , but when i'm searching for a record that exist the form just freez and the button disable but it don't show the record.??
    vb Code:
    1. Option Explicit
    2.        
    3. Private strDataBaseName As String
    4.          Private strDBCursorType As String
    5.          Private strDBLockType As String
    6.          Private strDBOptions As String
    7.          Private rs As ADODB.Recordset
    8.          Private cn As ADODB.Connection
    9.          Private strSQL As String
    10.          
    11.  
    12.       Private Sub Command1_Click()
    13.         Dim b As Long
    14.       On Error GoTo Command1_Click_Error
    15.         Me.Command1.Enabled = False
    16.        strDBCursorType = adOpenDynamic  'CursorType
    17.        strDBLockType = adLockOptimistic   'LockType
    18.         strDBOptions = adCmdText         'Options
    19.        
    20.         Set cn = New ADODB.Connection
    21.         Me.MousePointer = 11
    22.          
    23.       cn.Open ConnectString()
    24.          
    25.             With cn
    26.                .CommandTimeout = 0
    27.                 .CursorLocation = adUseClient
    28.             End With
    29.  
    30.        
    31.        
    32.             Set rs = New ADODB.Recordset       'Creates record set
    33.          
    34.             strSQL = "SELECT * "
    35.             strSQL = strSQL & "FROM filei "
    36.            strSQL = strSQL & "WHERE [File Extension] ='" & Me.Text1.Text & "' "
    37.           strSQL = strSQL & "ORDER BY [File Extension];"
    38.  
    39.        
    40.           rs.Open strSQL, cn, strDBCursorType, strDBLockType, strDBOptions
    41.  
    42.          
    43.           If Not rs.EOF Then
    44.                 For b = 1 To rs.RecordCount
    45.                        '<=== Do whatever you need to do with the recordset here
    46.                        rs.MoveNext
    47.                 Next b
    48.            Else
    49.               MsgBox "The recordset contained no Records"
    50.  
    51.           End If
    52.      
    53.  
    54.       Beep
    55.  
    56.        
    57.  
    58.       rs.Close
    59.        Set rs = Nothing
    60.         cn.Close
    61.         Set cn = Nothing
    62.  
    63.        
    64.  
    65.       On Error GoTo 0
    66.         Exit Sub
    67.  
    68.        
    69.  
    70. Command1_Click_Error:
    71.            MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure Command1_Click of Form " & Me.Name
    72.         End Sub
    73.  
    74.              Private Function ConnectString()
    75.             ConnectString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\Fido-Dido\Desktop\File_Identifier.mdb;"
    76.          
    77.         End Function

  8. #8
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: Search From The Database

    Could you print a sample of the data contained in the "filei" Table? Additionally, how many records are contained in that table?
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


  9. #9

    Thread Starter
    Frenzied Member met0555's Avatar
    Join Date
    Jul 2006
    Posts
    1,385

    Re: Search From The Database

    there are file extensions there are about 2000 records

  10. #10
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: Search From The Database

    Have you tried stepping through the code to see where it hangs up?
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


  11. #11

    Thread Starter
    Frenzied Member met0555's Avatar
    Join Date
    Jul 2006
    Posts
    1,385

    Re: Search From The Database

    I've tried with break points but i wasn't able to see where is the problem on the form i've only putted a button and a textbox does it need something else?

    thanks

  12. #12
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: Search From The Database

    Quote Originally Posted by met0555
    I've tried with break points but i wasn't able to see where is the problem on the form i've only putted a button and a textbox does it need something else?

    thanks
    So you were able to step through the code and it didn't hang up?
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


  13. #13
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Search From The Database

    This is part of Mark's initial example
    Code:
    If Not rs.EOF Then
                    For b = 1 To rs.RecordCount
                           '<=== Do whatever you need to do with the recordset here
                           rs.MoveNext
                    Next b
               Else
                  MsgBox "The recordset contained no Records"
      
              End If
    What did you replace
    Code:
     "'<=== Do whatever you need to do with the recordset here"
    with?

  14. #14

    Thread Starter
    Frenzied Member met0555's Avatar
    Join Date
    Jul 2006
    Posts
    1,385

    Re: Search From The Database

    it's because i didn't change it with the right code, but anyway i used another code but i still get an error, i will post on a new post.
    thanks

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