can't delete a record problem

ssfftt

Well-known member
Joined
Oct 27, 2005
Messages
163
Programming Experience
1-3
[solved]can't delete a record problem

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:
Just a side note. You never want to delete users. Make a bit column that's "blnActive." Chances are, you're going to have a plethora of table relationships tied to the UID. Deleting the user will a) fail because of a foreign key or b) orphan alot of records.
 
Back
Top