我很擅长使用数据库.现在我可以写SELECT,UPDATE,DELETE,和INSERT命令.但我看过很多我们喜欢写的论坛:
SELECT empSalary from employee where salary = @salary
Run Code Online (Sandbox Code Playgroud)
...代替:
SELECT empSalary from employee where salary = txtSalary.Text
Run Code Online (Sandbox Code Playgroud)
为什么我们总是喜欢使用参数以及如何使用它们?
我想知道第一种方法的用途和好处.我甚至听说过SQL注入,但我并不完全理解它.我甚至不知道SQL注入是否与我的问题有关.
我知道这很可能是一个愚蠢的问题,但我是一名大学生,他是C#和面向对象编程的新手.我试图在别处找到答案,但我找不到任何有用的东西.调试器一直告诉我变量'cust_num在当前上下文中不存在'.如果有人能告诉我我做错了什么并让我觉得自己像个白痴,我会非常感激.谢谢!
string get_cust_num()
{
bool cust_num_valid = false;
while (!cust_num_valid)
{
cust_num_valid = true;
Console.Write("Please enter customer number: ");
string cust_num = Console.ReadLine();
if (cust_num == "000000" || !Regex.IsMatch(cust_num, @"^[0-9]+$") || cust_num.Length != 6)
{
cust_num_valid = false;
Console.WriteLine("Invalid customer number detected. Customer numbers must be a 6 digit positive integer (zeros will not work)");
}
}
return cust_num;
}
Run Code Online (Sandbox Code Playgroud)