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. Create listbox based on contents of table

Create listbox based on contents of table

Scheduled Pinned Locked Moved Visual Basic
helpdatabaseannouncement
7 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.
  • P Offline
    P Offline
    penguin5000
    wrote on last edited by
    #1

    Newbie requiring help to something which is no doubt very simple! I have written a small application which gathers Company Name data from an Access table. I've also got a ValueMember set up which I am using to display the path to the mdb file used for the Company so that the user can see where the data is located, and it is also allowing me to offer the user a button so that they can open an Explorer window to go straight to the location of the file. My problem is that if the Company Name field is blank, I want to display some text (other than a blank) in the list box. The code snippet so far is: ********************************************* strConnString = "Jet OLEDB:Database Password .... blah, blah ... Provider=""Microsoft.Jet.OLEDB.4.0"";" Me.OleDbConnection1.ConnectionString = strConnString Me.OleDbSelectCommand1.CommandText = "SELECT CompanyId, CompanyName, FilePath FROM CompanyDetails WHERE (Version = '1') AND (Deleted = 0) ORDER BY CompanyName" Me.OleDbSelectCommand1.Connection = Me.OleDbConnection1 OleDbDataAdapter1.Fill(DsCentralDat1) ********************************************* This works well, and I can see the contents of my database in the listbox - its just that I can't get it to overwrite any blank entries in the listbox (if it finds any) with something which may be more meaningful to the user. Hope you can help.

    S 1 Reply Last reply
    0
    • P penguin5000

      Newbie requiring help to something which is no doubt very simple! I have written a small application which gathers Company Name data from an Access table. I've also got a ValueMember set up which I am using to display the path to the mdb file used for the Company so that the user can see where the data is located, and it is also allowing me to offer the user a button so that they can open an Explorer window to go straight to the location of the file. My problem is that if the Company Name field is blank, I want to display some text (other than a blank) in the list box. The code snippet so far is: ********************************************* strConnString = "Jet OLEDB:Database Password .... blah, blah ... Provider=""Microsoft.Jet.OLEDB.4.0"";" Me.OleDbConnection1.ConnectionString = strConnString Me.OleDbSelectCommand1.CommandText = "SELECT CompanyId, CompanyName, FilePath FROM CompanyDetails WHERE (Version = '1') AND (Deleted = 0) ORDER BY CompanyName" Me.OleDbSelectCommand1.Connection = Me.OleDbConnection1 OleDbDataAdapter1.Fill(DsCentralDat1) ********************************************* This works well, and I can see the contents of my database in the listbox - its just that I can't get it to overwrite any blank entries in the listbox (if it finds any) with something which may be more meaningful to the user. Hope you can help.

      S Offline
      S Offline
      Solid Snake
      wrote on last edited by
      #2

      i am just guessing now but try something like this if list1.additem = "" then (insert your code here)

      P 1 Reply Last reply
      0
      • S Solid Snake

        i am just guessing now but try something like this if list1.additem = "" then (insert your code here)

        P Offline
        P Offline
        penguin5000
        wrote on last edited by
        #3

        Thanks for that - but the listbox is, I think, already created and populated during the Fill process. What I'm struggling to do is get it to go and interogate the contents of dataset and build the listbox contents based on the condition that you've mentioned. I've thought about passing the contents of the database to an array, checking the contents, and passing that to the listbox, but I don't know how to do it. Any more thoughts?

        S 1 Reply Last reply
        0
        • P penguin5000

          Thanks for that - but the listbox is, I think, already created and populated during the Fill process. What I'm struggling to do is get it to go and interogate the contents of dataset and build the listbox contents based on the condition that you've mentioned. I've thought about passing the contents of the database to an array, checking the contents, and passing that to the listbox, but I don't know how to do it. Any more thoughts?

          S Offline
          S Offline
          Solid Snake
          wrote on last edited by
          #4

          nope, sorry. But experiment with some code and it will hit you like a ton of bricks sooner or later ;)

          M 1 Reply Last reply
          0
          • S Solid Snake

            nope, sorry. But experiment with some code and it will hit you like a ton of bricks sooner or later ;)

            M Offline
            M Offline
            mr_12345
            wrote on last edited by
            #5

            You could do the following in the query: SELECT IIf(IsNull([Test]),"Help",[TEST]) AS Expr1, TEST_TABLE.ID FROM TEST_TABLE;

            M 1 Reply Last reply
            0
            • M mr_12345

              You could do the following in the query: SELECT IIf(IsNull([Test]),"Help",[TEST]) AS Expr1, TEST_TABLE.ID FROM TEST_TABLE;

              M Offline
              M Offline
              mr_12345
              wrote on last edited by
              #6

              OR strConnString = "Jet OLEDB:Database Password .... blah, blah ... Provider=""Microsoft.Jet.OLEDB.4.0"";" Me.OleDbConnection1.ConnectionString = strConnString Me.OleDbSelectCommand1.CommandText = "SELECT CompanyId, CompanyName, FilePath FROM CompanyDetails WHERE (Version = '1') AND (Deleted = 0) ORDER BY CompanyName" Me.OleDbSelectCommand1.Connection = Me.OleDbConnection1 OleDbDataAdapter1.Fill(DsCentralDat1) dim row as datarow for each row in dsCentlralDat1.Tables("TableName").Rows if isDbNull(row.item("CompanyName") orelse row.item("CompanyName") = "" then row.item("CompanyName") = "What you want" end if next Me.DataSource = dsCentlralDat1.Tables("TableName") Me.DisplayMember = "CompanyName" Me.ValueMember = "CompanyId" -- modified at 22:46 Tuesday 18th April, 2006

              P 1 Reply Last reply
              0
              • M mr_12345

                OR strConnString = "Jet OLEDB:Database Password .... blah, blah ... Provider=""Microsoft.Jet.OLEDB.4.0"";" Me.OleDbConnection1.ConnectionString = strConnString Me.OleDbSelectCommand1.CommandText = "SELECT CompanyId, CompanyName, FilePath FROM CompanyDetails WHERE (Version = '1') AND (Deleted = 0) ORDER BY CompanyName" Me.OleDbSelectCommand1.Connection = Me.OleDbConnection1 OleDbDataAdapter1.Fill(DsCentralDat1) dim row as datarow for each row in dsCentlralDat1.Tables("TableName").Rows if isDbNull(row.item("CompanyName") orelse row.item("CompanyName") = "" then row.item("CompanyName") = "What you want" end if next Me.DataSource = dsCentlralDat1.Tables("TableName") Me.DisplayMember = "CompanyName" Me.ValueMember = "CompanyId" -- modified at 22:46 Tuesday 18th April, 2006

                P Offline
                P Offline
                penguin5000
                wrote on last edited by
                #7

                Thanks - this works brilliantly!! :-D

                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