Public Sub ComboboxRegionReload()
Dim cmds As New SqlCommand
Dim sqlC As String = ""
Dim dd As SqlDataReader
sqlC = "select Region_manager_name from P_D_Region_Manager"
ComboBox_M_Region.Text = ""
ComboBox_M_Region.Items.Clear()
With cmds
conn.Open()
.CommandType = CommandType.Text
.CommandText = sqlC
.Connection = conn
dd = .ExecuteReader()
While dd.Read()
ComboBox_M_Region.Items.Add(dd.GetString(0))
End While
End With
dd.Close()
ComboBox_M_Region.Text = "กรุณาเลือกข้อมูล" 'ใส่ตอน เรียกข้อมูลใส่ cobo เสร็จแล้ว
conn.Close()
End Sub
Tag : .NET, Ms SQL Server 2008, VS 2008 (.NET 3.x)
อันอื่นสามารถทำได้หมดคับ แต่ Sub นี้ทำไมถึงทำไม่ได้
Code (VB.NET)
Public Sub ReadConfig()
strConn = "Data Source=PTK530080085-PC\sqlexpress;Initial Catalog=TestProject;Integrated Security=True;Pooling=False"
End Sub
อันนี้ไว้เปิดคับ
ReadConfig()
With conn
If .State = ConnectionState.Open Then .Close()
.ConnectionString = strConn
.Open()
End With
With cmds
conn.Open()
.CommandType = CommandType.Text
.CommandText = sqlC
.Connection = conn
dd = .ExecuteReader()
While dd.Read()
ComboBox_M_Region.Items.Add(dd.GetString(0))
End While
End With
Public Function conn() As System.Data.OleDb.OleDbConnection
Dim cnn As New System.Data.OleDb.OleDbConnection
cnn.ConnectionString = "Data Source=PTK530080085-PC\sqlexpress;Initial Catalog=TestProject;Integrated Security=True;Pooling=False"
cnn.Open()
Return cnn
End Function
การใช้งาน
Code (VB.NET)
Public Sub ComboboxRegionReload()
Dim cmds As New SqlCommand
Dim sqlC As String = ""
Dim dd As SqlDataReader
sqlC = "select Region_manager_name from P_D_Region_Manager"
ComboBox_M_Region.Text = ""
ComboBox_M_Region.Items.Clear()
With cmds
.CommandType = CommandType.Text
.CommandText = sqlC
.Connection = conn
dd = .ExecuteReader()
While dd.Read()
ComboBox_M_Region.Items.Add(dd.GetString(0))
End While
End With
dd.Close()
ComboBox_M_Region.Text = "กรุณาเลือกข้อมูล" 'ใส่ตอน เรียกข้อมูลใส่ cobo เสร็จแล้ว
conn.Close()
End Sub