Results 1 to 7 of 7

Thread: darn it , no action at all [UN -Resolved yet]

  1. #1

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083

    darn it , no action at all [UN -Resolved yet]

    Hell , I dunno what the **** is going wrong with this code , no action at all .I hate it .Basically , I want to search my database.anyone has example or a link ....thanx for any help .
    VB Code:
    1. Private Sub Button2_Click(ByVal sender As System.Object _
    2. , ByVal e As System.EventArgs) Handles Button2.Click
    3.  
    4.         Dim MyConnection1 As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &  _
    5. MyPath & ";Jet OLEDB:Database Password=" & MyPassword)
    6.         Dim myDataReader As OleDbDataReader
    7.         Dim txt As String = "SELECT * FROM MyTab WHERE C_URL LIKE '" & TextBox7.Text.Replace("'", "''") & "*'"
    8.         Dim myOleDbCommand = New OleDbCommand(txt, MyConnection1)
    9.  
    10.         MyConnection1.Open()
    11.         myDataReader = myOleDbCommand.ExecuteReader()
    12.         Do While (myDataReader.Read)
    13.  
    14.             If (myDataReader.IsDBNull(0)) Then
    15.                 MsgBox(myDataReader.GetString(1))
    16.                 Console.Write("N/A" + Chr(10))
    17.                 MsgBox("no data")
    18.             Else
    19.                 Console.Write(myDataReader.GetInt32(4).ToString() + Chr(10))
    20.                 MsgBox(myDataReader.GetInt32(4).ToString() + Chr(10))
    21.             End If
    22.         Loop
    23.         myDataReader.Close()
    24.         MyConnection1.Close()
    25.  
    26.     End Sub
    Last edited by Pirate; Feb 7th, 2003 at 11:31 AM.

  2. #2

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    even C# code is accepted !

  3. #3

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    $bump$

  4. #4
    Addicted Member Nigh™a®e's Avatar
    Join Date
    Feb 2002
    Location
    Belgium
    Posts
    175
    Code:
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    
            Dim MyConnection1 As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &  _ 
    MyPath & ";Jet OLEDBatabase Password=" & MyPassword)
            Dim myDataReader As OleDbDataReader
            Dim txt As String = "SELECT * FROM MyTab WHERE C_URL LIKE '" & TextBox7.Text.Replace("'", "''") & "*'"
            Dim myOleDbCommand = New OleDbCommand(txt, MyConnection1)
    
            MyConnection1.Open()
            myDataReader = myOleDbCommand.ExecuteReader()
            Do While (myDataReader.Read)
    
                If (myDataReader.IsDBNull(0)) Then
                    MsgBox(myDataReader.GetString(1))
                    Console.Write("N/A" + Chr(10))
                    MsgBox("no data")
                Else
                    Console.Write(myDataReader.GetInt32(4).ToString() + Chr(10))
                    MsgBox(myDataReader.GetInt32(4).ToString() + Chr(10))
                End If
            Loop
            myDataReader.Close()
            MyConnection1.Close()
    
        End Sub

    Some things in your code are not totally clear .....

    1: Jet OLEDBatabase Password= never seen this param before, try to use UID=Admin;PWD=mypassword
    I used user ID Admin here. u should use this for sure if you are using a MS Access database.

    Code:
         "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &  _ 
         MyPath & ";Jet OLEDBatabase Password=" & MyPassword
    Code:
         "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &  _ 
         MyPath & ";UID=Admin;PWD=" & MyPassword

    ===

    2. Try to swap next 2 rules, open your dataconnection before creating the Command Object. Add the connection object to the New OleDBCommand rules to give the connction object to the command object.

    Code:
            Dim myOleDbCommand = New OleDbCommand(txt, MyConnection1)
    
            MyConnection1.Open()
    Code:
            MyConnection1.Open()
            Dim myOleDbCommand = New OleDbCommand(txt, MyConnection1, MyConnection1)
    ===

    3. Im allways using SQL Databases (used access long time ago)
    For Like clauses an asterix char will not work. I guess thats the same in access and most other databases. To search, use % instead of *

    Code:
    "*'"
    Code:
    "%'"
    ===

    I hope these changes make you app work.

    Greets Nightmare

    http://www.nightmare-products.com (Under construction)
    [email protected]

  5. #5

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Thanx for your the reply Nigh™a®e .I got another problem which says : "Couldn't find installable ISAM" .Open connection is highlighted . What's going wrong !
    I wish anyone gets me another way to search for records !

  6. #6
    Member EagleEye's Avatar
    Join Date
    May 2002
    Location
    South Carolina, USA
    Posts
    43
    I would be glad (as most of us would be I imagine) to take a look at it if you could post it.

    If that is not an option (understandable if it isn't) then may I suggest putting in some Try...Catch...End Try statements to possibly give you "more meaningful" error messages to help narrow the root cause. I have found this QUITE helpful when using databases.
    Eagle Eye

    "Programming is easy ... when you are done."

  7. #7

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Well , I always use the structure try ....catch to handle exceptions but I just can't seem to solve the problem .It must be something wrong with the connection string but it looks fine .Searching database in ADO.NET is a real pain !

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