我的代码有问题,没有错误显示,当我按下按钮时什么也没发生,这是代码im,第一个是更新按钮
Private Sub btnUpdate_Click(sender As Object, e As EventArgs) Handles btnUpdate.Click
Try
con.Open()
With cmd
.Connection = con
.CommandText = ("Update TBL_EMPLOYEE MiddleName='" & txtMiddleName.Text & "',LastName='" & txtLastName.Text & "', Gender='" & txtGender.Text & "',Age='" & txtupAge.Text & "' ,Address='" & txtupAddress.Text & "', Position='" & txtPos.Text & "',BirthDate='" & Bdate.Text & "' where [FirstName]=@FirstName ")
.Parameters.AddWithValue("FirstName", (txtFirstName.Text))
.ExecuteNonQuery()
.Dispose()
txtFirstName.Text = ""
txtMiddleName.Text = ""
txtLastName.Text = ""
txtGender.Text = ""
txtContactNumber.Text = ""
txtupAge.Text = ""
txtupAddress.Text = ""
txtPos.Text = ""
Bdate.Text = ""
PictureBox2.Image = Nothing
MsgBox("Product Updated", vbInformation, "Information Message")
datagridshow()
End With
Catch ex As Exception
End Try
End Sub
代码中没有错误显示,当我按下按钮时也没有任何反应,与删除按钮相同
Private Sub btnDelete_Click(sender As Object, e As EventArgs) Handles btnDelete.Click
Try
con.Open()
With cmd
.Connection = cn
.CommandText = "DELETE * from [TBL_EMPLOYEE] where FirstName='" & DataGridView2.CurrentRow.Cells(1).Value.ToString & "' "
.ExecuteNonQuery()
.Dispose()
.Parameters.Clear()
txtFirstName.Text = ""
txtMiddleName.Text = ""
txtLastName.Text = ""
txtGender.Text = ""
txtContactNumber.Text = ""
txtupAge.Text = ""
txtupAddress.Text = ""
txtPos.Text = ""
Bdate.Text = ""
PictureBox2.Image = Nothing
MsgBox("Employee Deleted", MsgBoxStyle.Information)
datagridshow()
End With
Catch ex As Exception
End Try
End Sub
没有错误,也没有任何反应 这是我正在使用的表格加载。
Dim str As String
str = ("Server=LOCALHOST\SQLEXPRESS;Database=Payroll;Trusted_Connection=True;")
cn = New SqlConnection(Str)
cn.Open()
答案 0 :(得分:3)
您的UPDATE缺少SET关键字,并且您的DELETE有一个*不应存在。