Deleting from database

Hi all

Getting late in the day, easy question possible, what am I doing wrong?

All I am trying to do is delete a row from Table EmployeeSkills, when SkillId = txtSkillId and employeeId  = txtemployeeId.

Help Please : ) Thanks


Private Sub btnDeleteSkill_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDeleteSkill.Click

        Dim Result As Integer = MsgBox("Confirm Delete of this Skill???", _
                MsgBoxStyle.OKCancel, "Deleting Skill")

        If Result = MsgBoxResult.OK Then

            Dim objCommand As SqlCommand = New SqlCommand()

            objCommand.Connection = objConnection
            objCommand.CommandText = "DELETE FROM EmployeeSkills " & _
            "Where EmployeeSkill.EmployeeId = '" & txtEmployeeId.Text & "' AND  EmployeeSkill.SkillId = '" & txtSkillId.Text & "' "

            objCommand.Parameters.Add("@EmployeeId", txtEmployeeId.Text)
            objCommand.Parameters.Add("@SkillId", txtSkillId.Text)




            StatusBar1.Text = "Record Deleted"


        ElseIf Result = MsgBoxResult.Cancel Then
            MsgBox("Please ammend and press Delete when correct, or cancel to end Deleting")
        End If
Andrew ParkerIT Field Systems Delivery OfficerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Are you getting an error or something?  If so, it would help to know what that error is.

I don't think you need to add the parameters... you're not using them in the sql statement.
Andrew ParkerIT Field Systems Delivery OfficerAuthor Commented:
The only error its giving is a system error

An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in

Additional information: System error.

occurs at line objCommand.ExecuteNonQuery()
Should DELETE FROM EmployeeSkills   be DELETE FROM EmployeeSkill

Exploring SQL Server 2016: Fundamentals

Learn the fundamentals of Microsoft SQL Server, a relational database management system that stores and retrieves data when requested by other software applications.

Andrew ParkerIT Field Systems Delivery OfficerAuthor Commented:
No, its employeeSkills
... also   are EmployeeID and SkillID character fields as you have them enclosed in quotes
Andrew ParkerIT Field Systems Delivery OfficerAuthor Commented:
EmployeeID & SkillId are set in 2 textboxes as Numbers
You're using both:

            objCommand.CommandText = "DELETE FROM EmployeeSkills " & _
            "Where EmployeeSkill.EmployeeId = '" & txtEmployeeId.Text & "' AND  EmployeeSkill.SkillId = '" & txtSkillId.Text & "' "

So if the table name is EmployeeSkills (with an s) then your where clause needs to use it too
EmployeeSkills.EmployeeId (not EmployeeSkill.EmployeeId)... etc etc

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
If EmployeeID & SkillID are defined on the database table as numeric, you cannot enclose in sigle quotes
Andrew ParkerIT Field Systems Delivery OfficerAuthor Commented:
Well spotted, like I said getting late here eyes are closing :)  pub soon I think

Thanks for your help that worked a treat :)
and as cubix is implying:
if EmployeeID and SkillID are defined as INT datatypes in the db, you need to pass INTs in the update statement.  I believe in you'd use CInt to cast them to integers.

"Where EmployeeSkills.EmployeeId = " & Cint(txtEmployeeId.Text) & " AND  EmployeeSkills.SkillId = " & CInt(txtSkillId.Text)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.