Dim strConn As String
strConn = DBConnString.strConn
Conn = New OleDbConnection()
With Conn
If .State = ConnectionState.Open Then .Close()
.ConnectionString = strConn
.Open()
End With
sb1 = New StringBuilder()
sb1.Append("SELECT * FROM tb_respon;")
Dim sqlrespon As String
sqlrespon = sb1.ToString()
Com = New OleDbCommand()
With Com
.CommandText = sqlrespon
.CommandType = CommandType.Text
.Connection = Conn
dr1 = .ExecuteReader()
End With
If dr1.HasRows Then
dtrespon = New DataTable()
dtrespon.Load(dr1)
With cb_rsp
.BeginUpdate()
.DisplayMember = "name_rpn"
.ValueMember = "id_rpn"
.DataSource = dtrespon
.EndUpdate()
End With
End If
Dim strConn As String
strConn = DBConnString.strConn
Conn = New OleDbConnection()
With Conn
If .State = ConnectionState.Open Then .Close()
.ConnectionString = strConn
.Open()
End With
'Dim daole As OleDb.OleDbDataAdapter สร้าง data adapter ซ่ะ
'Dim dt As DataTable = New DataTable สร้าง data table ซ่ะ
sb1 = New StringBuilder()
sb1.Append("SELECT * FROM tb_respon;")
Dim sqlrespon As String
sqlrespon = sb1.ToString()
Com = New OleDbCommand()
With Com
.CommandText = sqlrespon
.CommandType = CommandType.Text
.Connection = Conn
dr1 = .ExecuteReader()
'daole = New OleDb.SqlDataAdapter(Com)
'daole.Fill(dt) จับมันยัดลง databable
End With
If dr1.HasRows Then
dtrespon = New DataTable()
dtrespon.Load(dr1)
With cb_rsp
.BeginUpdate()
.DisplayMember = "name_rpn"
.ValueMember = "id_rpn"
.DataSource = dtrespon
.EndUpdate()
End With
End If
เอา data table "dt" ที่ได้ไปหา field "รายละเอียด" น่ะ โดยใช้ dt.Select("") เอาครับ
ถ้าไม่ใช่
ก็ต้อง query ใหม่โลด แล้วเอามาใส่ label
ไป query ใหม่ SELECT * FROM Table_ที่มี_field_รายละเอียด WHERE id = 'id ที่ combo box ได้มา'
Dim strConn As String
strConn = DBConnString.strConn
Conn = New OleDbConnection()
With Conn
If .State = ConnectionState.Open Then .Close()
.ConnectionString = strConn
.Open()
End With
sb1 = New StringBuilder()
sb1.Append("SELECT * FROM tb_respon;")
Dim sqlrespon As String
sqlrespon = sb1.ToString()
Com = New OleDbCommand()
With Com
.CommandText = sqlrespon
.CommandType = CommandType.Text
.Connection = Conn
dr1 = .ExecuteReader()
End With
If dr1.HasRows Then
dtrespon = New DataTable()
dtrespon.Load(dr1)
With cb_rsp
.BeginUpdate()
.DisplayMember = "name_rpn"
.ValueMember = "id_rpn"
.DataSource = dtrespon
.EndUpdate()
End With
End If
แล้วก็เอา ID มาเป็นเงื่อนไข (VB.NET)
Sub DropDownList_SelectedIndexChanged(sender as Object, e As System.EventArgs) Handles DropDownList.SelectedIndexChanged
Dim strConn As String
strConn = DBConnString.strConn
Conn = New OleDbConnection()
With Conn
If .State = ConnectionState.Open Then .Close()
.ConnectionString = strConn
.Open()
End With
sb1 = New StringBuilder()
sb1.Append("SELECT * FROM tb_respon WHERE Column_Name ='" & cb_rsp.Selectedvalue &"'")
Dim sqlrespon As String
sqlrespon = sb1.ToString()
Com = New OleDbCommand()
With Com
.CommandText = sqlrespon
.CommandType = CommandType.Text
.Connection = Conn
dr1 = .ExecuteReader()
End With
If dr1.HasRows Then
'ให้แสดงรายละเอียด ก็ว่ากันไป
End If
End Sub