⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 update.vb

📁 在本实例中
💻 VB
📖 第 1 页 / 共 2 页
字号:
        'Label8
        '
        Me.Label8.Location = New System.Drawing.Point(8, 132)
        Me.Label8.Name = "Label8"
        Me.Label8.Size = New System.Drawing.Size(56, 16)
        Me.Label8.TabIndex = 15
        Me.Label8.Text = "雇用日期"
        '
        'Txtaddress
        '
        Me.Txtaddress.Location = New System.Drawing.Point(72, 216)
        Me.Txtaddress.Name = "Txtaddress"
        Me.Txtaddress.Size = New System.Drawing.Size(96, 21)
        Me.Txtaddress.TabIndex = 22
        Me.Txtaddress.Text = ""
        '
        'Label9
        '
        Me.Label9.Location = New System.Drawing.Point(8, 221)
        Me.Label9.Name = "Label9"
        Me.Label9.Size = New System.Drawing.Size(56, 16)
        Me.Label9.TabIndex = 21
        Me.Label9.Text = "地    址"
        '
        'Txtpath
        '
        Me.Txtpath.Location = New System.Drawing.Point(232, 96)
        Me.Txtpath.Name = "Txtpath"
        Me.Txtpath.Size = New System.Drawing.Size(96, 21)
        Me.Txtpath.TabIndex = 23
        Me.Txtpath.Text = ""
        '
        'Label10
        '
        Me.Label10.Location = New System.Drawing.Point(192, 101)
        Me.Label10.Name = "Label10"
        Me.Label10.Size = New System.Drawing.Size(32, 16)
        Me.Label10.TabIndex = 24
        Me.Label10.Text = "图片"
        '
        'OpenFileDialog1
        '
        Me.OpenFileDialog1.InitialDirectory = "C:\"
        '
        'Pibox
        '
        Me.Pibox.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
        Me.Pibox.Location = New System.Drawing.Point(192, 128)
        Me.Pibox.Name = "Pibox"
        Me.Pibox.Size = New System.Drawing.Size(136, 112)
        Me.Pibox.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage
        Me.Pibox.TabIndex = 25
        Me.Pibox.TabStop = False
        '
        'Btsave
        '
        Me.Btsave.Location = New System.Drawing.Point(336, 176)
        Me.Btsave.Name = "Btsave"
        Me.Btsave.Size = New System.Drawing.Size(40, 23)
        Me.Btsave.TabIndex = 26
        Me.Btsave.Text = "保存"
        '
        'Btexit
        '
        Me.Btexit.Location = New System.Drawing.Point(336, 208)
        Me.Btexit.Name = "Btexit"
        Me.Btexit.Size = New System.Drawing.Size(40, 23)
        Me.Btexit.TabIndex = 27
        Me.Btexit.Text = "退出"
        '
        'Btopen
        '
        Me.Btopen.Location = New System.Drawing.Point(336, 96)
        Me.Btopen.Name = "Btopen"
        Me.Btopen.Size = New System.Drawing.Size(40, 23)
        Me.Btopen.TabIndex = 28
        Me.Btopen.Text = "打开"
        '
        'update
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
        Me.ClientSize = New System.Drawing.Size(384, 245)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Btopen, Me.Btexit, Me.Btsave, Me.Pibox, Me.Label10, Me.Txtpath, Me.Txtaddress, Me.Label9, Me.Txtdescript, Me.Label4, Me.Txtsal, Me.Txttel, Me.Txthiredate, Me.Label5, Me.Label6, Me.Label8, Me.Txtdeptno, Me.Label7, Me.TxteName, Me.Txttitle, Me.TxtemployeeID, Me.Label3, Me.Label2, Me.Label1})
        Me.Name = "update"
        Me.Text = "数据更新"
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private Sub Btopen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btopen.Click

        '打开图片
        Dim openFileDialog1 As New OpenFileDialog()
        openFileDialog1.InitialDirectory = "c:\"
        openFileDialog1.Filter = "jpg files (*.jpg)|*.jpg|gif files (*.gif)|*.gif|All files (*.*)|*.*"
        openFileDialog1.FilterIndex = 2
        '存储目录
        openFileDialog1.RestoreDirectory = True

        If openFileDialog1.ShowDialog() = DialogResult.OK Then
            '在文本框中显示图片的路径
            Dim path As String
            path = openFileDialog1.FileName
            Txtpath.Text = path
            '在pinturebox中显示图片
            Pibox.SizeMode = PictureBoxSizeMode.StretchImage
            Pibox.Image = Image.FromFile(path)
        End If

    End Sub
    '        TxteName.Text = ""
    '        Txttitle.Text = ""
    '        Txtdeptno.Text = ""
    '        Txtdescript.Text = ""
    '        Txthiredate.Text = ""
    '        Txtsal.Text = ""
    '        Txttel.Text = ""
    '        Txtaddress.Text = ""

    Private Sub Btsave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btsave.Click

        '定义一个例外
        Dim ex As Exception
        '判断用户输入是否完整
        If TxtemployeeID.Text = "" Then
            MessageBox.Show("请输入雇员编号", "信息框", _
          MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            Exit Sub

        ElseIf TxteName.Text = "" Then
            MessageBox.Show("请输入雇员姓名", "信息框", _
        MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            Exit Sub

        ElseIf Txttitle.Text = "" Then
            MessageBox.Show("请输入雇员职务", "信息框", _
        MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            Exit Sub

        ElseIf Txtdeptno.Text = "" Then
            MessageBox.Show("请输入雇员部门号", "信息框", _
        MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            Exit Sub

        ElseIf Txthiredate.Text = "" Then
            MessageBox.Show("请输入雇用日期", "信息框", _
        MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            Exit Sub

        ElseIf Txtsal.Text = "" Then
            MessageBox.Show("请输入雇员薪金", "信息框", _
        MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            Exit Sub

        ElseIf Txtpath.Text = "" Then
            MessageBox.Show("请先选择图片", "信息框", _
        MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            Exit Sub

        End If

        '数据库操作
        Try
            Dim strInsert As String
            Dim myconn As OleDb.OleDbConnection
            Dim mycmd As OleDb.OleDbCommand
            myconn = New OleDb.OleDbConnection("Provider=SQLOLEDB;Data Source=qianzh;" & _
                                                               "Integrated Security=SSPI;Initial Catalog=employ")
            myconn.Open()
            strInsert = "INSERT INTO employees (employeeid, eName, title,deptno) VALUES ( '" & _
                        TxtemployeeID.Text & "','" & TxteName.Text & "','" & Txttitle.Text & "','" & Txtdeptno.Text & "')"
            mycmd = New OleDb.OleDbCommand(strInsert, myconn)

            '直接对数据库进行更新操作
            mycmd.ExecuteNonQuery()
            myconn.Close()


            Dim adoConn As ADODB.Connection = New ADODB.Connection()
            Dim mstream As ADODB.Stream
            Dim rs As ADODB.Recordset = New ADODB.Recordset()
            adoConn.Open("dsn=myServer;uid=;pwd=;")
            rs.Open("SELECT * FROM employees where employeeid='" & TxtemployeeID.Text & "'", adoConn, ADODB.CursorTypeEnum.adOpenKeyset, ADODB.LockTypeEnum.adLockOptimistic)
            mstream = New ADODB.Stream()
            mstream.Type = ADODB.StreamTypeEnum.adTypeBinary
            mstream.Open()
            Dim path As String
            path = Txtpath.Text
            mstream.LoadFromFile(path)
            rs.Fields("image").Value = mstream.Read
            rs.Update()
            rs.Close()
            adoConn.Close()

            MessageBox.Show("成功保存!", "信息框", _
     MessageBoxButtons.OK, MessageBoxIcon.Exclamation)

        Catch ex
            MessageBox.Show("添加数据出错" & ex.ToString(), "错误")
        End Try
        '以下清空显示
        TxtemployeeID.Text = ""
        TxteName.Text = ""
        Txttitle.Text = ""
        Txtdeptno.Text = ""
        Txtdescript.Text = ""
        Txthiredate.Text = ""
        Txtsal.Text = ""
        Txttel.Text = ""
        Txtaddress.Text = ""
        Txtpath.Text = ""
        '   清空图片 
        Pibox.Image = Nothing
    End Sub

    Private Sub Btexit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btexit.Click

        If MessageBox.Show("确定退出吗" & TxtemployeeID.Text & "," & TxteName.Text & "的资料", "确认", _
            MessageBoxButtons.YesNo, MessageBoxIcon.Question) _
              = DialogResult.Yes Then
            Close()
        End If

    End Sub
End Class

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -