dimanche 14 avril 2019

C# If statement for SQL

I am using WinForms and I want to use SQL if statement in my code.

Here is a small example. I am using SQL long query and I want to use IF statement to do two different functions. Here is example.

        string query = "SELECT U1.UserID, U1.FirstName, U1.LastName, C1.UserID, C1.FriendID FROM USERS U1 inner Join Chat C1 on U1.UserID = C1.UserID Where C1.UserID = '" + MyName.Uid + "' and C1.FriendID = '" + friendid + "' or C1.UserID = '" + friendid + "' and C1.FriendID = '" + MyName.Uid + "' ORDER BY C1.ChatID";

There is some more stuff in there. But here is what I need. I know this gonna be wrong, I need someone to help me to write correct if statement.

  if (C1.UserID = '" + MyName.Uid + "' and C1.FriendID = '" + friendid + "')
      {
        //some code.
      }

Aucun commentaire:

Enregistrer un commentaire