hi,

My Problem is when am deleting a row from the SQL Server Database....I need to check two conditions.

For eg: While deleting a row from the database,i need to check based upon the Name of the Employee and The Employee Number.

Because there might be Employees with the same Name but differenet Employee Number.

dim sql as string

sql = "DELETE FROM Employees WHERE Emp_Name='" & Txt_EmpName.Text.Trim & "'".....// Here can I add one more condition ie Employee Number in the Where clause.

Anyone...please help me.

Thanks lot

Cheers

B.H

Recommended Answers

All 4 Replies

Currently:

sql = "DELETE FROM Employees WHERE Emp_Name='" & Txt_EmpName.Text.Trim & "'"

Outputs (example employee name = Joe):
sql = "DELETE FROM Employees WHERE Emp_Name='Joe'"

What I think you want:

sql = "DELETE FROM Employees WHERE Emp_Name='" & Txt_EmpName.Text.Trim & "' AND Emp_Number=" & Txt_EmpNumber.Trim

Outputs (example employee name (number) = Joe(2)):
sql = "DELETE FROM Employees WHERE Emp_Name='Joe' AND Emp_Number=2"

I'm assuming you have the employee number stored as an integer (or other number type), if it is stored as text you will need to add single quotes around the Txt_EmpNumber.Trim call.

I Tried the way u told me...but its showing error....do u have any other idea..thnks bro for replying to my doubt.

if u can help me with any other code that thinks can help me to work out the solution quickly..it would be greatly appreciatable.

Thanks once again for ur help

sql = "DELETE FROM Employees WHERE Emp_Name='" & Txt_Name.Text.Trim & "' AND Emp_Number= " & Txt_Empno.Text.Trim & ""
cnn.Execute(sqldelete)
End Sub

As I said, if you have the employee number stored as text, the SQL statement requires single quotes around it. As follows (do not include the double parentheses, they are there to show the difference between '" and "):

sql = "DELETE FROM Employees WHERE Emp_Name='" & Txt_Name.Text.Trim & "' AND Emp_Number= (('))" & Txt_Empno.Text.Trim & "(('))"

Thanks bro..urs worked..sorry 4 da late reply.

cheers

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.