Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does "WHERE x = ?" mean in SQL

Tags:

c#

sql

This code is written in C# and it is calling database to get the data from it. But I don't understand what does "WHERE b.CompRec = ?" mean

    public string GetFileNameAndTitle(int compRec)
    {
        string fileNameAndTitle = "";
        string sql = "SELECT a.FileName, a.Title FROM (Files a INNER JOIN Components b ON a.RecNo=b.FileRec) WHERE b.CompRec = ?";
        using (OleDbCommand cmd = new OleDbCommand(sql, cn))
        {               
            cmd.Parameters.AddWithValue("@CompRec", compRec);
            OpenConnection();    }
like image 607
S5498658 Avatar asked Nov 22 '25 11:11

S5498658


1 Answers

It is a parameterized statement.

cmd.Parameters.AddWithValue("@CompRec", compRec);

That line sets the actual value when the query is executed at the server. This prevents SQL Injection and is the 100% right approach!

like image 175
Mike Perrenoud Avatar answered Nov 25 '25 02:11

Mike Perrenoud



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!