Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/flash/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 要声明变量的数据库_C#_Database - Fatal编程技术网

C# 要声明变量的数据库

C# 要声明变量的数据库,c#,database,C#,Database,我确实想将StudName内容传递给我声明的变量。我尝试了“+a.ToString+”,但仍然出现了错误 string a; connection.Close(); connection.Open(); String strSQL = "select *from Students where StudName = '" +a.ToString() + "' and StudNum = '" + studentNumber; OleDbCommand command = new OleDbCo

我确实想将StudName内容传递给我声明的变量。我尝试了“+a.ToString+”,但仍然出现了错误

string a;

connection.Close();
connection.Open();
String strSQL = "select *from Students where StudName = '"  +a.ToString() + "' and StudNum = '" + studentNumber;
OleDbCommand command = new OleDbCommand(strSQL);
StudNum='“+studentNumber

studentNumber的数据库列是数字列,但您有一半将其视为字母数字

解决方案

StudNum=“+studentNumber


您需要使用参数化的命令来执行此操作。这还将解决一些问题,例如包含撇号的变量等,这些问题也会导致sql失败。

错误是什么?为什么我们要试着猜测你显示器上的信息?这段代码中有很多问题。请使用参数d instrad连接字符串。了解sql注入注意sql注入!警觉的!