Results 1 to 3 of 3

Thread: Populating dropdownlist with data

  1. #1

    Thread Starter
    Hyperactive Member greg_quinn's Avatar
    Join Date
    Nov 2002
    Location
    South Africa
    Posts
    366

    Populating dropdownlist with data

    I'm an asp.net programmer and am getting my feet wet with windows apps in visual studio.net.

    I can populate a dropdownlist on a web page with

    Dim sql as String = "Select Id, NAme from Table"
    Dim objCommand As New OdbcCommand(sql, objConnection)
    objConnection.Open()
    Dim objDataReader As OdbcDataReader
    objDataReader = objCommand.ExecuteReader()

    myList.DataSource = objDataReader
    myList.DataBind()

    objDataReader.Close()
    objConnection.Close()
    End Sub

    But in vs.net in my windows app it tells me that Databind is not a member of comboBox.

    What is the easiest way to populate a dropdownlist in vs.net for a windows app.

    Thanks

  2. #2
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Hi,

    Not sure about Web Pages, but in ordinary VB.NET as well as setting A combobox datasource, you need to

    VB Code:
    1. cboName1.DisplayMember = "PlayerName"
    2.             cboName1.ValueMember = "PlayerID"

    (copied from one of my projects)
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  3. #3
    Fanatic Member brown monkey's Avatar
    Join Date
    Jun 2004
    Location
    Cebu
    Posts
    552
    sorry for bothers... just want to add something...
    VB Code:
    1. Dim cn As New OdbcConnection()
    2.    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    3.       cn.ConnectionString = "driver={mysql odbc 3.51 driver};database=temp"
    4.       cn.Open()
    5.    End Sub
    6.  
    7.    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    8.       Dim cmdtext As String = "insert into xtable values('" & TextBox1.Text & "','" & TextBox2.Text & "')"
    9.       Dim cm As New OdbcCommand(cmdtext, cn)
    10.       cm.ExecuteNonQuery()
    11.    End Sub
    12.  
    13.    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    14.       Dim cmdtext As String = "select * from xtable"
    15.  
    16.       Dim da As New OdbcDataAdapter()
    17.       da.SelectCommand = New OdbcCommand(cmdtext, cn)
    18.  
    19.       Dim dt As New DataTable()
    20.       da.Fill(dt)
    21.  
    22.       With ComboBox1
    23.          .DataSource = dt
    24.          .DisplayMember = "xname"
    25.          .ValueMember = "xid"
    26.       End With
    27.    End Sub
    hope this helps...

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