[solved]can't delete a record problem
can anyone help to fix this piece of code for deleting a user in my user table?
seems that the error is from "SqlDeleteCommand2.ExecuteNonQuery()"
btw, the sql in SqlDeleteCommand2 is "DELETE FROM CYMUSER
WHERE (UNAME = @UNAME)"
can anyone help to fix this piece of code for deleting a user in my user table?
VB.NET:
Private Sub btnUnregister_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUnregister.Click
SqlConnectionUserLogin.Open()
'get inputs
SqlCommandUserLogin.Parameters("@UNAME").Value = txtLoginName.Text.Trim
SqlCommandUserLogin.Parameters("@PW").Value = txtLoginPW.Text.Trim
'validate inputs
If CInt(SqlCommandUserLogin.ExecuteScalar()) = 0 Then
MessageBox.Show("Invalid User!")
Else
SqlDeleteCommand2.ExecuteNonQuery()
MessageBox.Show("User Removed!")
End If
SqlConnectionUserLogin.Close()
End Sub
seems that the error is from "SqlDeleteCommand2.ExecuteNonQuery()"
btw, the sql in SqlDeleteCommand2 is "DELETE FROM CYMUSER
WHERE (UNAME = @UNAME)"
Last edited: