开发者

problem with parameters of the query

开发者 https://www.devze.com 2023-03-19 23:28 出处:网络
I\'m having troubles passing parameters to a query throws this exception The parameterized query \'(@IdIndicador int)INSERT INTO [AtentoMIG].[dbo].[Indicador]([Nom\' expects the parameter \'@IdIndica

I'm having troubles passing parameters to a query throws this exception

The parameterized query '(@IdIndicador int)INSERT INTO [AtentoMIG].[dbo].[Indicador]([Nom' expects the parameter '@IdIndicador', which was not supplied.

this is my code

_sqlCommand = new SqlCommand
              ("INSERT INTO [AtentoMIG].[dbo].[Indicator]"                      
                  + "([Name]"
                  + ",[De开发者_如何学Cscripction])"
                  + "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;

Why am i doing wrong?? for me the code looks good


You forgot to supply the direction of the SqlParameter. Try adding:

SqlParameter idIndicador = new SqlParameter("@IdIndicador", SqlDbType.Int);
idIndicator.Direction = ParameterDirection.Output;
// ...
0

精彩评论

暂无评论...
验证码 换一张
取 消