Whoever has taught you this syntax has really taught you a wrong thing.
This syntax, as you have guessed, joins the content of the string txtSlipID_srch
to your SQL text forming a complete instruction from a fixed text and a variable part. The whole thing is then passed to the database engine for the execution.
But allowing a user to type something in a textbox and then using that input to build your SQL queries is really a wrong thing
The user can type anything and that anything could also be a well forged string that changes your intent and destroys your database or gets information that you don't want him to see (passwords or credit card numbers). It is called Sql Injection and there are thousands of articles on how to implement this hacking technique. I don't want to repeat anything, you could simply look at this well known comics+question+answers and read the explanations below
Apart from this. There is the problem of the correct parsing of strings. The presence of a single quote inside in your string variable will render your query invalid because single quotes are used to delimit string values passed to the database. The same happens with decimals and dates that should be transformed in strings with a conversion procedure. Also here you should create the correct text for the database (Does it like a comma or point for decimals?, the format for dates is 'dd/MM/yyyy' or 'MM/dd/yyyy' or what? and so on)
The only valid approach is to use a parameterized query where you write your command text in this way
selectSQL = "SELECT * FROM slip WHERE slip_id=@id";
Now there is no more the concatenation of the two strings and no single quotes around string values to 'escape' them, but just a parameter placeholder named @id
.
The ADO.NET library will provide the appropriate classes to handle that parameter, passing the value to the database engine where it will be treated correctly.
SqlCommand cmd = new SqlCommand(selectSQL, connection);
cmd.Parameters.Add("@id", SqlDbType.NVarChar).Value = txtSlipID_srch;
SqlDataReader reader = cmd.ExecuteReader();
......