📄 form6.vb
字号:
Imports System.Data.SqlClient
Imports System.Data
Public Class Form6
Dim bindpage As BindingManagerBase
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
TextBox5.Text = ""
If TextBox1.Text = "" Then
MessageBox.Show("请输入查询条件!")
Else
Dim odr As SqlClient.SqlDataReader
Dim ocmd As SqlClient.SqlCommand
Dim strconn As String
Dim strsql As String
strconn = "Data Source=x34;" & "Initial Catalog=student;" & "User ID=sa;" & "Password=;"
strsql = "select name,class,sex,number,xuhao from xs where number='" & TextBox1.Text & " '" 'and number='" & TextBox2.Text & "'"
ocmd = New SqlClient.SqlCommand()
With ocmd
.Connection = New SqlClient.SqlConnection(strconn)
.Connection.Open()
.CommandText = strsql
odr = .ExecuteReader
End With
If odr.Read() Then
With odr
TextBox2.Text = .Item("name").ToString()
TextBox3.Text = .Item("class").ToString()
TextBox4.Text = .Item("sex").ToString()
TextBox5.Text = .Item("number").ToString()
TextBox6.Text = .Item("xuhao").ToString
End With
End If
odr.Close()
ocmd.Connection.Close()
If TextBox2.Text = "" Then
MessageBox.Show("没有该同学资料!")
Else
begin()
End If
End If
If TextBox2.Text <> "" Then
Label9.ForeColor = Color.Red
Label9.Text = TextBox2.Text
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Me.Close()
End Sub
Private Sub Form6_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
TextBox2.Enabled = False
TextBox3.Enabled = False
TextBox4.Enabled = False
TextBox5.Enabled = False
TextBox6.Enabled = False
Label6.ForeColor = Color.Red
Label6.Text = "暂无照片"
End Sub
Public Sub begin()
Dim da2 As SqlDataAdapter
Dim cb2 As SqlCommandBuilder
Dim ds2 As New DataSet
Dim conn2 As New SqlConnection("Server=(local);DataBase=student;Integrated Security=SSPI;Connect Timeout=5")
Dim sql2 As New SqlCommand("SELECT photo FROM xs", conn2)
Try
da2 = New SqlDataAdapter(sql2)
cb2 = New SqlCommandBuilder(da2)
da2.Fill(ds2, "xs")
bindpage = Me.BindingContext(ds2, "xs")
Catch e1 As Exception
MsgBox(e1.ToString)
Finally
conn2.Close()
End Try
Try
Dim arrPicture() As Byte = CType(ds2.Tables(0).Rows(CInt(TextBox6.Text) - 1)("photo"), Byte())
Dim ms2 As New IO.MemoryStream(arrPicture)
'显示 Image
With PictureBox1
.Image = Image.FromStream(ms2)
.BorderStyle = BorderStyle.Fixed3D
End With
ms2.Close()
Catch ex As Exception
MessageBox.Show("暂无照片!")
End Try
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -