Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
textbox1.Text = ComboBox1.SelectedItem
End Sub
Jx_Man
Nearly a Senior Poster
3,329 posts since Nov 2007
Reputation Points: 1,372
Solved Threads: 444
what database that u using on?sqlserver or access?
Jx_Man
Nearly a Senior Poster
3,329 posts since Nov 2007
Reputation Points: 1,372
Solved Threads: 444
this following code to read data and display on combo box, u just put on event like "form load":
Public Function GetConnect()
Dim conn As SqlConnection
conn = New SqlConnection("server = jery;database = VBtoC#;Trusted_Connection = yes")
Return conn
End Function
Private Sub ReadData()
Dim i As Integer
Dim cmdStudent As New SqlCommand
Dim daStudent As New SqlDataAdapter
Dim dsStudent As New DataSet
Dim dtStudent As New DataTable
Dim conn As SqlConnection
conn = GetConnect()
Try
cmdStudent = conn.CreateCommand
cmdStudent.CommandText = "SELECT * FROM Student"
daStudent.SelectCommand = cmdStudent
daStudent.Fill(dsStudent, "Student") ' Table Name
dtStudent = dsStudent.Tables("Student") 'Table Name
For i = 0 To dtStudent.Rows.Count - 1
cmbNis.Items.Add(dtStudent.Rows(i).Item(0))
Next
Catch ex As Exception
MsgBox("Error: " & ex.Source & ": " & ex.Message, MsgBoxStyle.OKOnly, "Connection Error !!")
End Try
conn.Close()
End Sub
Hope this helps..
Jx_Man
Nearly a Senior Poster
3,329 posts since Nov 2007
Reputation Points: 1,372
Solved Threads: 444
yes, data will display on combo box. in my code id student will display on combo box.
Jx_Man
Nearly a Senior Poster
3,329 posts since Nov 2007
Reputation Points: 1,372
Solved Threads: 444
so combo box item is not retrived from database??
let user choose the item frm combo box then retrived the data from databse and view it.
what was retrived from database?and what to viewed?
how about your database table?
Jx_Man
Nearly a Senior Poster
3,329 posts since Nov 2007
Reputation Points: 1,372
Solved Threads: 444
i have read your other thread. i guest you do this in smart device, right?
i never do this in smart device...
Jx_Man
Nearly a Senior Poster
3,329 posts since Nov 2007
Reputation Points: 1,372
Solved Threads: 444
maybe missing reference :
Click Project menu and click Add Reference.
Microsoft.WindowsCE.Forms
System.Data.Common
System.Data.SqlServerCE
System.Windows.Forms
Set the references then we will import SqlServerCE namespace.
for more clearly see this link
Jx_Man
Nearly a Senior Poster
3,329 posts since Nov 2007
Reputation Points: 1,372
Solved Threads: 444