Click here to Skip to main content
15,867,453 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

How to join 3 conditions at 1 query so messagebox pops up to say 3 condition is fullfilled ?

If NewData Then
        strSQL =
            " SELECT Count(tblContact.Fullname, ) AS CountFullname FROM tblContact " &
            " WHERE Fullname = " & "'" & txtFullname.Text & "'"


" SELECT Count(tblContact.Phone, ) AS CountPhone FROM tblContact " &
     " WHERE Phone = " & "'" & txtPhone.Text & "'"



" SELECT Count(tblContact.email, ) AS Countemail FROM tblContact " &
     " WHERE email = " & "'" & txtemail.Text & "'"


What I have tried:

Forums, clauses, sample codes.
Posted
Updated 12-Mar-19 12:06pm

This is basically the same issue as How to add 3 IF conditions at VB - Visual Basic Discussion Boards[^]. And I note you are still not using parameterised queries, so your database is still at risk of corruption or worse.
 
Share this answer
 
v2
I fixed your SQL Injection problem too.... You may have to adjust syntax as my IDE's are all occupied so I'm writing this direct
C#
StringBuilder sb = new Stringbuilder("SELECT ");
sb.AppendLine("NameCount = (SELECT Count(1) FROM tblContact WHERE FullName = @FullName)");
sb.AppendLine(", PhoneCount = (SELECT Count(1) FROM tblContact WHERE Phone = @Phone)");
sb.AppendLine(", EmailCount = (SELECT Count(1) FROM tblContact WHERE Email = @Email)");


string strSQL = sb.ToString();
SqlCommand cmd = new SqlCommand(strSql, "connection");
cmd.Parameters.AddWithValue("@FullName", txtFullname.Text);
cmd.Parameters.AddWithValue("@Phone", txtPhone.Text);
cmd.Parameters.AddWithValue("@Email", txtemail.Text);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900