Dim sqlfind As String = ""
Dim comm As New SqlCommand
Dim dr As SqlDataReader
If txtFind.Text = "" Then
Exit Sub
End If
If Conn.State = ConnectionState.Open Then Conn.Close()
Conn.Open()
Dim sql1 As String = ""
If ComboBox1.Text = "รหัสนักศึกษา" Then
sql1 = "id_std"
ElseIf ComboBox1.Text = "ชื่อ - สกุล" Then
sql1 = "name"
End If
Try
sqlfind = "select * from e_std where (" & sql1 & "='" & txtFind.Text & "')"
With comm
.CommandType = CommandType.Text
.CommandText = sqlfind
.Connection = Conn
dr = .ExecuteReader()
dr.Read()
lblID.Text = CStr(dr.Item("id_std"))
txtID.Text = CStr(dr.Item("id_std"))
txtName.Text = CStr(dr.Item("name"))
lblname.Text = CStr(dr.Item("name"))
txtYear.Text = CStr(dr.Item("yearcome"))
txtDepart.Text = CStr(dr.Item("depart"))
txtTopic.Text = CStr(dr.Item("topic"))
GBstd.Visible = True
dr.Close()
ConnFind2()
ConnFind3()
End With
Catch ex As Exception
MessageBox.Show("ไม่มีรหัสนักศึกษาหรือชื่อนักศึกษาคนนี้ กรุณากรอกข้อมูลเพื่อค้นหาใหม่!!! ", "ผลการค้นหา", MessageBoxButtons.OK, MessageBoxIcon.Information)
txtFind.Focus()
txtFind.SelectAll()
End Try
Tag : .NET, Ms SQL Server 2008, Web (ASP.NET), VB.NET, VS 2008 (.NET 3.x)