开发者

problem with parameters of the query

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜