| | |
How to give 2 Conditions in an SQL Query
Please support our VB.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Aug 2006
Posts: 13
Reputation:
Solved Threads: 0
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
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
Currently:
Outputs (example employee name = Joe):
sql = "DELETE FROM Employees WHERE Emp_Name='Joe'"
What I think you want:
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.
VB.NET Syntax (Toggle Plain Text)
sql = "DELETE FROM Employees WHERE Emp_Name='" & Txt_EmpName.Text.Trim & "'"
sql = "DELETE FROM Employees WHERE Emp_Name='Joe'"
What I think you want:
VB.NET Syntax (Toggle Plain Text)
sql = "DELETE FROM Employees WHERE Emp_Name='" & Txt_EmpName.Text.Trim & "' AND Emp_Number=" & Txt_EmpNumber.Trim
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.
Please anyone, correct me if I am wrong. It is the best way for me to learn.
•
•
Join Date: Aug 2006
Posts: 13
Reputation:
Solved Threads: 0
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
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 & "(('))" Please anyone, correct me if I am wrong. It is the best way for me to learn.
![]() |
Similar Threads
- SQL query problem with WHERE clause (ASP)
- Please help me out with MySQL query (MySQL)
- PHP/SQL query help (PHP)
- Retreiving variables from a sql query into a form (PHP)
Other Threads in the VB.NET Forum
- Previous Thread: B.Sc Thesis Project
- Next Thread: ComboBox bind data problem
| Thread Tools | Search this Thread |
.net .net2008 2005 2008 access account arithmetic array arrays basic bing button buttons c# center check checkbox code combobox convert crystalreport data database datagrid datagridview date dissertation dissertations dropdownlist excel fade file-dialog filter ftp generatetags google gridview hardcopy images inline input insert intel internet listview mobile monitor ms net networking objects output panel passingparameters picturebox picturebox1 port position print printing problem project read remove save searchbox searchvb.net select serial server shutdown soap sorting survey table tcp temperature text textbox timer timespan toolbox trim update user validation vb vb.net vb.netformclosing()eventpictureboxmessagebox vb2008 vbnet view visual visualbasic visualbasic.net visualstudio2008 web winforms wpf year





