我的老是插不了数据库里面 错误是 已有打开的与此连接相关联的DATAreader,必须将它关闭 哪个高手帮帮忙..谢了 Dim ue As New UnicodeEncoding Dim pwd() As Byte = ue.GetBytes(txtpwd.Text) Dim sha As New SHA1Managed Dim pw() As Byte = sha.ComputeHash(pwd) Dim empid As Integer = FormListEmployee.empid
Dim modify As New SqlCommand Dim str As String = "UPDATE tblEmployee SET Name = @txtname, LoginName = @txtloginname, Password = @pwd, Email = @txtEmail, BasicSalary = @txtbasicsalary, EmployeeLevel = @numLevel, Title = @txttitle, Telephone = @txtphone, PhotoImage = @picPhoto WHERE (EmployeeID = @empid)" modify.CommandText = str modify.Connection = SqlConnection1 modify.Parameters.Add(New System.Data.SqlClient.SqlParameter("@txtname", System.Data.SqlDbType.NVarChar, 50, "Name")) modify.Parameters.Add(New System.Data.SqlClient.SqlParameter("@txtloginname", System.Data.SqlDbType.NVarChar, 20, "LoginName")) modify.Parameters.Add(New System.Data.SqlClient.SqlParameter("@pwd", System.Data.SqlDbType.VarBinary, 20, "Password")) modify.Parameters.Add(New System.Data.SqlClient.SqlParameter("@txtEmail", System.Data.SqlDbType.NVarChar, 50, "Email")) modify.Parameters.Add(New System.Data.SqlClient.SqlParameter("@txtbasicsalary", System.Data.SqlDbType.Int, 4, "BasicSalary")) modify.Parameters.Add(New System.Data.SqlClient.SqlParameter("@numLevel", System.Data.SqlDbType.Int, 4, "EmployeeLevel")) modify.Parameters.Add(New System.Data.SqlClient.SqlParameter("@txttitle", System.Data.SqlDbType.NVarChar, 50, "Title")) modify.Parameters.Add(New System.Data.SqlClient.SqlParameter("@txtphone", System.Data.SqlDbType.NVarChar, 50, "Telephone")) modify.Parameters.Add(New System.Data.SqlClient.SqlParameter("@picPhoto", System.Data.SqlDbType.VarBinary, 16, "PhotoImage")) modify.Parameters.Add(New System.Data.SqlClient.SqlParameter("@empid", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "EmployeeID", System.Data.DataRowVersion.Original, Nothing)) ' modify.Parameters("@txtname").Value = txtname.Text modify.Parameters("@txtname").Direction = ParameterDirection.Input modify.Parameters("@txtloginname").Value = txtloginname.Text modify.Parameters("@txtloginname").Direction = ParameterDirection.Input modify.Parameters("@pwd").Value = pw modify.Parameters("@pwd").Direction = ParameterDirection.Input modify.Parameters("@txtEmail").Value = txtEmail.Text modify.Parameters("@txtEmail").Direction = ParameterDirection.Input modify.Parameters("@txtbasicsalary").Value = txtbasicsalary.Text modify.Parameters("@txtbasicsalary").Direction = ParameterDirection.Input modify.Parameters("@numLevel").Value = numLevel.Text modify.Parameters("@numLevel").Direction = ParameterDirection.Input modify.Parameters("@txttitle").Value = txttitle.Text modify.Parameters("@txttitle").Direction = ParameterDirection.Input modify.Parameters("@txtphone").Value = txtphone.Text modify.Parameters("@txtphone").Direction = ParameterDirection.Input Dim FormPhotoPath As New FormPhotoPath If File.Exists(FormPhotoPath.path) Then
Dim fs As FileStream = File.OpenRead(FormPhotoPath.path) Dim abytes() As Byte abytes = Array.CreateInstance(GetType(Byte), fs.Length) fs.Read(abytes, 0, fs.Length) modify.Parameters("@picPhoto").Value = abytes modify.Parameters("@picPhoto").Direction = ParameterDirection.Input
fs.Close() End If
modify.Parameters("@empid").Value = empid modify.Parameters("@empid").Direction = ParameterDirection.Input
Try SqlConnection1.Open()
If modify.ExecuteNonQuery Then MessageBox.Show("修改成功!", "提示") End If Catch ex As Exception MessageBox.Show("修改失败!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error) Finally If SqlConnection1.State = ConnectionState.Open Then
SqlConnection1.Close() End If End Try
End Sub