C# 尝试在winforms中使用存储过程。visual studio 2015表示close toy“出现错误”&引用;

C# 尝试在winforms中使用存储过程。visual studio 2015表示close toy“出现错误”&引用;,c#,sql-server,winforms,visual-studio,stored-procedures,C#,Sql Server,Winforms,Visual Studio,Stored Procedures,代码如下: 我试着大胆一点。这是我的一部分 您有一个语法错误: + **bold**", " 应改为: + **bold** + ", " 尽管我不知道**bold**是什么如果存储过程需要varchar或char参数,则需要用单引号将参数括起来 SqlCommand comando = new SqlCommand("spObtenerMarca '" + auxiliar1 + "', '" + auxiliar2 + "'", conexion @DavidG对SQL注入提出了一个有

代码如下: 我试着大胆一点。这是我的一部分


您有一个语法错误:

+ **bold**", "
应改为:

+ **bold** + ", "

尽管我不知道**bold**是什么

如果存储过程需要varchar或char参数,则需要用单引号将参数括起来

SqlCommand comando = new SqlCommand("spObtenerMarca '" + auxiliar1 + "', '" + auxiliar2 + "'", conexion
@DavidG对SQL注入提出了一个有效的观点。您应该将代码更改为使用参数,而不是合并和传递命令字符串

根据未包括示例的批评:

...
SqlCommand comando = new SqlCommand("spObtenerMarca", conexion);
comando.Parameters.AddWithValue("@parameter1", auxiliar1);
comando.Parameters.AddWithValue("@parameter2", auxiliar2);
SqlDataReader reader = comando.ExecuteReader();
...

这里有一千个关于如何创建所有存储过程的问题,请查找其中一些。您在这里所做的不仅是错误的,而且是危险的(去查找SQL注入攻击)哈哈,谢谢,那是因为我试图将错误变为粗体,这不是原始代码中的错误。最好向OP展示如何使用命令参数抵御SQL注入攻击。。不知道OP是怎么用双引号编译代码的。
...
SqlCommand comando = new SqlCommand("spObtenerMarca", conexion);
comando.Parameters.AddWithValue("@parameter1", auxiliar1);
comando.Parameters.AddWithValue("@parameter2", auxiliar2);
SqlDataReader reader = comando.ExecuteReader();
...