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. how i can fetch list box with Names vb. net?

how i can fetch list box with Names vb. net?

Scheduled Pinned Locked Moved Visual Basic
helptutorialquestion
4 Posts 2 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.
  • R Offline
    R Offline
    RaveRare
    wrote on last edited by
    #1

    Dear everyone. hope you all will be fine and good in health. i have a problem that i want to fetch a listbox with names. please help me that what code i have to write. PICTURE IS HERE; i have a table STUDENT with attributes (ID, Name, Age) i have inserted 100 students record into STUDENT tabl i have a listbox control named lstStdents on my form now i want that when my form is opened, it should auotmatically fill the listbox with NAME of students i want to know that how to fill that box using datareader? thanks

    M 1 Reply Last reply
    0
    • R RaveRare

      Dear everyone. hope you all will be fine and good in health. i have a problem that i want to fetch a listbox with names. please help me that what code i have to write. PICTURE IS HERE; i have a table STUDENT with attributes (ID, Name, Age) i have inserted 100 students record into STUDENT tabl i have a listbox control named lstStdents on my form now i want that when my form is opened, it should auotmatically fill the listbox with NAME of students i want to know that how to fill that box using datareader? thanks

      M Offline
      M Offline
      Michael Sync
      wrote on last edited by
      #2

      http://msdn2.microsoft.com/en-us/library/haa3afyz(VS.71).aspx Try like that. OleDbConnection nwindConn = new OleDbConnection("Provider=MSDataShape;Data Provider=SQLOLEDB;" + "Data Source=localhost;Integrated Security=SSPI;Initial Catalog=northwind"); OleDbCommand custCMD = new OleDbCommand("SELECT Name from STUDENT", nwindConn); nwindConn.Open(); OleDbDataReader custReader = custCMD.ExecuteReader(); while (custReader.Read()) { Listbox1.AddItem(custReader.GetString(1) = CompanyName); } custReader.Close(); nwindConn.Close(); do searching a lit bit. man.... there are a lot of examples about how to populate the data into listbox in web or our forum....

      Thanks and Regards, Michael Sync ( Blog: http://michaelsync.net) If you want to thank me for my help, please vote my message by clicking one of numbers beside "Rate this message". Why vote? Plz Read it here. Thank you. :)

      R 1 Reply Last reply
      0
      • M Michael Sync

        http://msdn2.microsoft.com/en-us/library/haa3afyz(VS.71).aspx Try like that. OleDbConnection nwindConn = new OleDbConnection("Provider=MSDataShape;Data Provider=SQLOLEDB;" + "Data Source=localhost;Integrated Security=SSPI;Initial Catalog=northwind"); OleDbCommand custCMD = new OleDbCommand("SELECT Name from STUDENT", nwindConn); nwindConn.Open(); OleDbDataReader custReader = custCMD.ExecuteReader(); while (custReader.Read()) { Listbox1.AddItem(custReader.GetString(1) = CompanyName); } custReader.Close(); nwindConn.Close(); do searching a lit bit. man.... there are a lot of examples about how to populate the data into listbox in web or our forum....

        Thanks and Regards, Michael Sync ( Blog: http://michaelsync.net) If you want to thank me for my help, please vote my message by clicking one of numbers beside "Rate this message". Why vote? Plz Read it here. Thank you. :)

        R Offline
        R Offline
        RaveRare
        wrote on last edited by
        #3

        Dear Micheal thanks for nice information i have writen my code following your pattern but it not works Dim con As New OleDb.OleDbConnection("Provider=Microsoft.jet.oledb.4.0;Data Source=e:\college.mdb") Dim query As New OleDb.OleDbCommand("Select * from student") con.Open() Dim dr As OleDb.OleDbDataReader = query.ExecuteReader() While (dr.Read()) ListBox1.Items.Add(dr.GetString(1) = Name) End While dr.Close() con.Close() please help me more to clear my concept thanks

        M 1 Reply Last reply
        0
        • R RaveRare

          Dear Micheal thanks for nice information i have writen my code following your pattern but it not works Dim con As New OleDb.OleDbConnection("Provider=Microsoft.jet.oledb.4.0;Data Source=e:\college.mdb") Dim query As New OleDb.OleDbCommand("Select * from student") con.Open() Dim dr As OleDb.OleDbDataReader = query.ExecuteReader() While (dr.Read()) ListBox1.Items.Add(dr.GetString(1) = Name) End While dr.Close() con.Close() please help me more to clear my concept thanks

          M Offline
          M Offline
          Michael Sync
          wrote on last edited by
          #4

          Egoest wrote:

          Dim query As New OleDb.OleDbCommand("Select * from student")

          Select **Name** from student

          Egoest wrote:

          ListBox1.Items.Add(dr.GetString(1) = Name)

          ListBox1.Items.Add(dr.GetString(1))

          Thanks and Regards, Michael Sync ( Blog: http://michaelsync.net) If you want to thank me for my help, please vote my message by clicking one of numbers beside "Rate this message". Why vote? Plz Read it here. Thank you. :)

          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