我的insert语句总是执行两次,这是我的代码:
Private Sub NewEmployee()
Dim MS As New MemoryStream
Dim Images() As Byte
If (pbEmpPhoto.Image IsNot Nothing) Then
pbEmpPhoto.Image.Save(MS, pbEmpPhoto.Image.RawFormat)
Images = MS.GetBuffer
MS.Close()
End If
' Adds Parameters
Access.AddParam("@empid", tbEmpID.Text)
Access.AddParam("@lname", tbLastName.Text)
Access.AddParam("@fname", tbFirstName.Text)
Access.AddParam("@address", tbAddress.Text)
Access.AddParam("@contact", tbContact.Text)
Access.AddParam("@dept", cbDept.SelectedItem)
Access.AddParam("@position", cbPosition.SelectedItem)
Access.AddParam("@emppic", IIf(pbEmpPhoto.Image IsNot Nothing, Images, DBNull.Value))
' Execute Insert Command
Access.ExecQuery("INSERT INTO EmployeeInfo (EmployeeID,Fname,Lname,Address,[Contact],Department,[Position],EmployeePic) VALUES (@empid,@fname,@lname,@address,@contact,@position,@dept,@emppic); ")
' Reports And Aborts on Errors
If Not String.IsNullOrEmpty(Access.Exception) Then MsgBox(Access.Exception) : Exit Sub
' Success Message
MessageBox.Show("Registration Successful!", "New Employee", MessageBoxButtons.OK, MessageBoxIcon.Asterisk)
RG.RefreshGrid()
pbEmpPhoto.Image = Nothing
Exit Sub
Me.Close()
End Sub
Access来自我创建的类,这里是执行sub:
的地方Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
NewEmployee()
End Sub
我该如何解决这类问题?请帮我。先感谢您。