Results 1 to 32 of 32

Thread: Search db [Sorted by Edneeis]

  1. #1

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

    Talking Search db [Sorted by Edneeis]

    I need any code that search access db . I looked around , I've tried to do it myself but all with no luck . . any help would be appreciated .
    thanx
    Last edited by Pirate; Feb 22nd, 2003 at 12:45 AM.

  2. #2
    Member
    Join Date
    Dec 2002
    Location
    NY, USA
    Posts
    52
    Can you use SQL
    "select * from Table where Field = 'YourCriteria'"

    After that execute Reader if you expect to return sevral records or Scalar if it is only one record
    Iouri Boutchkine

  3. #3

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Originally posted by Iouri
    Can you use SQL
    "select * from Table where Field = 'YourCriteria'"
    After that execute Reader if you expect to return sevral records or Scalar if it is only one record
    I've tried a lot but all didn't work !!! if you have any example for this that would be great !
    thanx for your reply

  4. #4

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Right now I am using this but error everywhere
    VB Code:
    1. Public Sub searchit()
    2.         Dim str() As String
    3.         Dim MyReader As OleDbDataReader
    4.         MyConnection.Open()
    5.         Dim comd As New OleDbCommand("SELECT * FROM MyTab WHERE C_URL = [url]www.hotmail.com[/url]", MyConnection)
    6.         Try
    7.             MyReader = comd.ExecuteReader()
    8.         Catch x As Exception
    9.             MsgBox(x.Message)
    10.         End Try
    11.         Try
    12.             While MyReader.Read
    13.                 str(0) = MyReader("C_URL")
    14.                 str(1) = MyReader("C_Category")
    15.                 str(2) = MyReader("C_language")
    16.                 str(3) = MyReader("C_username")
    17.  
    18.             End While
    19.         Catch x As Exception
    20.             MsgBox(x.Message)
    21.         End Try
    22. end sub

  5. #5

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    error msg say this : "no value given for one or more required parameters"

    and this part is highlighted :

    VB Code:
    1. MyReader = comd.ExecuteReader()
    same error same line . What am I doing wrong here !
    Last edited by Pirate; Feb 21st, 2003 at 11:02 PM.

  6. #6

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Originally posted by Iouri
    Can you use SQL
    "select * from Table where Field = 'YourCriteria'"

    After that execute Reader if you expect to return sevral records or Scalar if it is only one record
    When I use this SQL Statement the first error isn't shown :
    VB Code:
    1. ("SELECT * FROM MyTab WHERE C_URL = 'www.hotmail.com'"
    but another error is shown saying :
    "Object reference not set to an instance of an object" and this part is highlighted :

    MyReader.Close()

    I think I have to instantiate new obj of datareader .I couldn't because new method is private .
    any thoughts

  7. #7
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Try moving the reader declaration intot he try block although it should work fine the way you have it.

    VB Code:
    1. Public Sub searchit()
    2.         Dim str() As String
    3.         Dim MyReader As OleDbDataReader
    4.         MyConnection.Open() 'I assume this is intialized and given a connection string else where in our code
    5.         Dim comd As New OleDbCommand("SELECT * FROM MyTab WHERE C_URL = 'www.hotmail.com'", MyConnection)'Yeah need the quotes since hotmail is a string
    6.         Try
    7.             Dim MyReader As OleDbDataReader= comd.ExecuteReader()
    8.             While MyReader.Read
    9.                 str(0) = MyReader("C_URL")
    10.                 str(1) = MyReader("C_Category")
    11.                 str(2) = MyReader("C_language")
    12.                 str(3) = MyReader("C_username")
    13.  
    14.             End While
    15.         Catch x As Exception
    16.             MsgBox(x.Message)
    17.         End Try
    18. end sub
    Last edited by Edneeis; Feb 21st, 2003 at 10:57 PM.

  8. #8

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Thanx Ed . What is stored procedure by the way !! I've read a lot of articles that talks about it !

  9. #9
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    A stored procedure is a lot like a query in an access database but WAY more powerfull. They are generally in SQL Server and probably Oracle too. They are compiled and so they run faster and you can do a lot more with them including run multiple queries or loop or a bunch of different things.
    Last edited by Edneeis; Feb 21st, 2003 at 11:32 PM.

  10. #10

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Originally posted by Pirate
    error msg say this : "no value given for one or more required parameters"

    and this part is highlighted :
    VB Code:
    1. MyReader = comd.ExecuteReader()
    same error same line . What am I doing wrong here !

  11. #11

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    How can I instantiate new object from datareader .It keeps throwing this error :
    "Object reference not set to an instance of an object" ?????
    damn MS ! ADO.NET is a real pain in the ass .

  12. #12
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Sounds like maybe your query isn't returning anything or something to that extent.

  13. #13

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Originally posted by Edneeis
    Sounds like maybe your query isn't returning anything or something to that extent.
    What do you think of "Find" method that exist in datarow object ??Isn't more easier than this crap although I've not used it be4 !

  14. #14
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    I started making an example for you and realized something. The problem is from the string array. You didn't initialize it to any length so you can't refer to different dimensions in it.
    Change:
    Dim str() as string
    To:
    Dim str(3) as string

    And everything will work fine.

  15. #15

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    I thought this is only in C# , You have to initialize it so you can use it. anyways , I will try it now

  16. #16
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Anyway here is that example if you want it.

  17. #17

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Originally posted by Edneeis
    Anyway here is that example if you want it.
    Edneeis , you are best of the best in this forum . Thank you
    dude !

  18. #18

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Now 90 % of the problem was solved what left is how can I search with initial letter of a word !!!!!!! I hate this part . It sucks .
    Thanks a lot for your help so far .

  19. #19
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Well I don't know about the best of the best but I'm glad I could help. Thanks.

  20. #20

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Originally posted by Pirate
    Now 90 % of the problem was solved what left is how can I search with initial letter of a word !!!!!!! I hate this part . It sucks .
    Thanks a lot for your help so far .
    What about this part ? any ideas .

  21. #21
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Try putting this in the textbox as of the DataReader example: www.h%
    or
    w%

    Nevermind I screwed up on the example and forgot something. Give me a sec.

  22. #22

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Originally posted by Edneeis
    Try putting this in the textbox as of the DataReader example: www.h%
    or
    w%
    in the code . If yes . Then how if I want to look for another word stats in E for example ????
    Thank you

  23. #23
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Ok change the btnReader click event to this in the example:
    VB Code:
    1. Private Sub btnReader_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReader.Click
    2.         'here is the code for using the data reader way
    3.         'first setup the connection
    4.         Dim MyConnection As New OleDbConnection(CnnStr)
    5.         Dim result As New ArrayList()
    6.         'setup the command to get the data
    7.         'if you want to enter partial data then use Like instead of = and the % symbol as a wildcard
    8.         Dim comd As New OleDbCommand("SELECT * FROM MyTab WHERE C_URL Like '" & txtReader.Text & "'", MyConnection)
    9.         'open the connection
    10.         MyConnection.Open()
    11.         Try
    12.             'now the reader to read the results
    13.             Dim MyReader As OleDbDataReader = comd.ExecuteReader()
    14.             'read until the end
    15.             While MyReader.Read
    16.                 result.Add(MyReader.Item("C_URL"))
    17.                 result.Add(MyReader.Item("C_Category"))
    18.                 result.Add(MyReader.Item("C_language"))
    19.                 result.Add(MyReader.Item("C_username"))
    20.                 result.Add(ControlChars.NewLine)
    21.             End While
    22.         Catch x As Exception
    23.             'oops trouble show the exception
    24.             MsgBox(x.StackTrace, MsgBoxStyle.Exclamation, x.Message)
    25.         Finally
    26.             'now clean up
    27.             MyConnection.Close()
    28.             MyConnection.Dispose()
    29.             comd.Dispose()
    30.         End Try
    31.         'now show the result if any
    32.         If result.Count > 0 Then
    33.             Dim resultStr As String = Join(result.ToArray, " ")
    34.             MsgBox(resultStr, , "It worked here is the results")
    35.         End If
    36.     End Sub

  24. #24

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    I'm sorry for disturbing you but where should I put this sign "%" ??

  25. #25

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    got it now . Thank you thank you Edneeis .

  26. #26
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Its no disturbance. In SQL the % works like the * its a wildcard so you can place it at the end of a search criteria to match the start of a word or in the middle to match a pattern. So in the example change the www.hotmail.com text in the textbox of the data reader example to whatever search criteria you want.

    w% would return all entries that start with w

    www.h% will return all entries that start with www.h

    Both of those don't care what comes after the % it just matches the start of the word.

    If you want a pattern then you can put stuff after the % as well:

    www.v%.com would return all entries that start with www.v and end in .com

    w%.net would return all entries that start with w and end in .net

    Likewise with things in the middle although this can be more tricky:

    w%v% will return all entries that start with w and have a v somewhere after that

    Oopps I was already writing my post when you responded. You can add more data to the database, especially similar entries, to get a better feel of using the % symbol in a query.

  27. #27

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    One more quick question !!
    Is it possible to add all possible matches to listbox and it deletes or adds as I type depending on the word I am looking for ? if so plz just give me a hint .
    lot of thanks for those great posts .

  28. #28
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Here is an updated example with what you are looking for. Is this for your web browser app?

  29. #29

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    How did you know about that !!!!
    Did you hack me ????

  30. #30
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Yes I did

    I remember a while ago you asked a bunch of questions on the subject and about the autocomplete feature of a combobox.

  31. #31

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Originally posted by Edneeis
    Here is an updated example with what you are looking for. Is this for your web browser app?
    exactly what I wanted to do .
    That's enough Edneeis . You've done all the part concerning search db .
    Thank you so so so so so much for those helpful posts .
    have a nice day dude !

  32. #32

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Originally posted by Edneeis
    Yes I did

    I remember a while ago you asked a bunch of questions on the subject and about the autocomplete feature of a combobox.
    that's right . Now I can keep my unique proj up .I will finish it soon.
    see ya

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