|
-
Jun 19th, 2004, 01:39 PM
#1
Thread Starter
Hyperactive Member
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
-
Jun 20th, 2004, 03:44 PM
#2
PowerPoster
Hi,
Not sure about Web Pages, but in ordinary VB.NET as well as setting A combobox datasource, you need to
VB Code:
cboName1.DisplayMember = "PlayerName"
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.
-
Jun 20th, 2004, 10:16 PM
#3
Fanatic Member
sorry for bothers... just want to add something...
VB Code:
Dim cn As New OdbcConnection()
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
cn.ConnectionString = "driver={mysql odbc 3.51 driver};database=temp"
cn.Open()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim cmdtext As String = "insert into xtable values('" & TextBox1.Text & "','" & TextBox2.Text & "')"
Dim cm As New OdbcCommand(cmdtext, cn)
cm.ExecuteNonQuery()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim cmdtext As String = "select * from xtable"
Dim da As New OdbcDataAdapter()
da.SelectCommand = New OdbcCommand(cmdtext, cn)
Dim dt As New DataTable()
da.Fill(dt)
With ComboBox1
.DataSource = dt
.DisplayMember = "xname"
.ValueMember = "xid"
End With
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|