Sql = "SELECT * FROM Employee "
Dim Cmd As New SqlCommand(Sql, Cls.Con)
Dim Rs As SqlDataReader = Cmd.ExecuteReader
If Rs.Read Then
combobox1.text=Rs("levell")
Endif
Imports System.Data.SqlClient
Imports System.Data
Public Class W_Combobox
Private Function GetASDtbl(ByVal tsql As String) As DataTable 'Function Connect SQL Return DataTable
GetASDtbl = Nothing
Dim Con As New SqlConnection
Dim DTat As SqlDataAdapter
Dim Dtbl As New DataTable
Try
With Con
If .State = ConnectionState.Open Then .Close()
.ConnectionString = "server=localhost;uid=sa;pwd=123456;database=7project"
.Open()
End With
DTat = New SqlDataAdapter(tsql, Con)
DTat.Fill(Dtbl)
GetASDtbl = Dtbl
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Function
Private Function GetAsCombo() As Boolean 'Function Add Combobox
Dim tsql As String = "SELECT levell FROM Update_sa"
Dim Dtbl As New DataTable
Dtbl = GetASDtbl(tsql)
If ComboBox1.Items.Count > 0 Then
ComboBox1.Items.Clear()
End If
For Each Drow As DataRow In Dtbl.Rows
ComboBox1.Items.Add(Drow("levell"))
Next
End Function
Private Sub W_Combobox_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load 'Form Load
GetAsCombo()
End Sub
End Class