我遇到麻烦将参数传递给查询会引发此异常
参数化查询'(@IdIndicador int)INSERT INTO [AtentoMIG]。[dbo]。[Indicador]([Nom'期望参数'@IdIndicador',未提供。 < / p>
这是我的代码
_sqlCommand = new SqlCommand
("INSERT INTO [AtentoMIG].[dbo].[Indicator]"
+ "([Name]"
+ ",[Descripction])"
+ "VALUES"
+ "('" + data[0] + "'"
+ ",'" + data[13] + "') SET @IdIndicador = SCOPE_IDENTITY()", _sqlConexion);
SqlParameter idIndicador = new SqlParameter("@IdIndicador", SqlDbType.Int);
_sqlCommand.Parameters.Add(idIndicador);
_sqlCommand.Connection.Open();
_sqlCommand.ExecuteNonQuery();
int id = (int)idIndicador.Value;
_sqlConexion.Close();
return true;
为什么我做错了?对我来说,代码看起来不错
答案 0 :(得分:2)
You forgot to supply the direction of the SqlParameter
。尝试添加:
SqlParameter idIndicador = new SqlParameter("@IdIndicador", SqlDbType.Int);
idIndicator.Direction = ParameterDirection.Output;
// ...