Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Database help

Database help

Scheduled Pinned Locked Moved Visual Basic
helpdatabaseregex
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Binary0110
    wrote on last edited by
    #1

    I experimenting with Writing database applications and trying to do different things with different controls. My current problem is I've been working on a feature to search a database containg my DVD collection. It is an Access 2003 Database with only one table. Here is my code thus far with the area where the program bombs in bold, any help would be greatly appreciated.Also the code that is supposed to check for a database is'nt working either, but I commented it out for now: 'Search 'If they have no active dataset, refuse: 'If ds.Tables.Count = 0 Then ' MsgBox("Please use the file menu to open a dataset, or create 'a new one first.") ' Exit Sub 'End If 'search for the target in both columns, then display it Dim searchfor As String = InputBox("Enter you Search Term", "Search") searchfor = searchfor.ToLower lstResults.Items.Clear() Dim i, x, y, count As Integer **dt = ds.Tables!DVDLIST ' set dt to point to this table** TotalRows = dt.Rows.Count For i = 0 To TotalRows - 1 x = ds.Tables(Name).Rows(i).Item(0).ToString.ToLower.IndexOf(searchfor) 'See if Title column matches y = ds.Tables(0).Rows(i).Item(1).ToString.ToLower.IndexOf(searchfor) 'see about desc column too If x <> -1 Or y <> -1 Then 'Match lstResults.Items.Add(ds.Tables(0).Rows(i).Item(0)) 'Add title field to a listbox count += 1 End If Next i If count = 0 Then 'no matches found MsgBox("No match for " & searchfor & " was found...") Else lstResults.Visible = True End If BINARY

    C 1 Reply Last reply
    0
    • B Binary0110

      I experimenting with Writing database applications and trying to do different things with different controls. My current problem is I've been working on a feature to search a database containg my DVD collection. It is an Access 2003 Database with only one table. Here is my code thus far with the area where the program bombs in bold, any help would be greatly appreciated.Also the code that is supposed to check for a database is'nt working either, but I commented it out for now: 'Search 'If they have no active dataset, refuse: 'If ds.Tables.Count = 0 Then ' MsgBox("Please use the file menu to open a dataset, or create 'a new one first.") ' Exit Sub 'End If 'search for the target in both columns, then display it Dim searchfor As String = InputBox("Enter you Search Term", "Search") searchfor = searchfor.ToLower lstResults.Items.Clear() Dim i, x, y, count As Integer **dt = ds.Tables!DVDLIST ' set dt to point to this table** TotalRows = dt.Rows.Count For i = 0 To TotalRows - 1 x = ds.Tables(Name).Rows(i).Item(0).ToString.ToLower.IndexOf(searchfor) 'See if Title column matches y = ds.Tables(0).Rows(i).Item(1).ToString.ToLower.IndexOf(searchfor) 'see about desc column too If x <> -1 Or y <> -1 Then 'Match lstResults.Items.Add(ds.Tables(0).Rows(i).Item(0)) 'Add title field to a listbox count += 1 End If Next i If count = 0 Then 'no matches found MsgBox("No match for " & searchfor & " was found...") Else lstResults.Visible = True End If BINARY

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      I don't see a bold line.

      Binary0110 wrote:

      searchfor = searchfor.ToLower

      Is Access case sensitive ? SQL Server isn't.

      Binary0110 wrote:

      ds.Tables!DVDLIST

      What does this do ?

      Binary0110 wrote:

      For i = 0 To TotalRows - 1 x = ds.Tables(Name).Rows(i).Item(0).ToString.ToLower.IndexOf(searchfor) 'See if Title column matches y = ds.Tables(0).Rows(i).Item(1).ToString.ToLower.IndexOf(searchfor) 'see about desc column too If x <> -1 Or y <> -1 Then 'Match lstResults.Items.Add(ds.Tables(0).Rows(i).Item(0)) 'Add title field to a listbox count += 1 End If Next i

      This is definately not how to write a database. You may as well store your data in text files if you're not going to use SQL to search through your data. "SELECT * from DVDList where title LIKE '%" + searchfor +"' OR desc LIKE '%" + searchfor + "'" would generate you something that would have a good shot of giving you what you need. I suggest you google for "Access VB.NET Connection" and see what you come up with. Christian Graus - Microsoft MVP - C++

      J 1 Reply Last reply
      0
      • C Christian Graus

        I don't see a bold line.

        Binary0110 wrote:

        searchfor = searchfor.ToLower

        Is Access case sensitive ? SQL Server isn't.

        Binary0110 wrote:

        ds.Tables!DVDLIST

        What does this do ?

        Binary0110 wrote:

        For i = 0 To TotalRows - 1 x = ds.Tables(Name).Rows(i).Item(0).ToString.ToLower.IndexOf(searchfor) 'See if Title column matches y = ds.Tables(0).Rows(i).Item(1).ToString.ToLower.IndexOf(searchfor) 'see about desc column too If x <> -1 Or y <> -1 Then 'Match lstResults.Items.Add(ds.Tables(0).Rows(i).Item(0)) 'Add title field to a listbox count += 1 End If Next i

        This is definately not how to write a database. You may as well store your data in text files if you're not going to use SQL to search through your data. "SELECT * from DVDList where title LIKE '%" + searchfor +"' OR desc LIKE '%" + searchfor + "'" would generate you something that would have a good shot of giving you what you need. I suggest you google for "Access VB.NET Connection" and see what you come up with. Christian Graus - Microsoft MVP - C++

        J Offline
        J Offline
        jcrussell
        wrote on last edited by
        #3

        I could barely work out what he was trying to do - got my 5 for the translation to SQL /jason

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups