代码之家  ›  专栏  ›  技术社区  ›  Xion

如何使用参数化sql更新sql代理作业

  •  0
  • Xion  · 技术社区  · 7 年前

    在我的项目中,我希望通过使用odbc.net提供程序执行sql参数化存储过程来更新sql代理作业。到目前为止,这就是我所拥有的

    OdbcCommand ExecJob = new OdbcCommand();           
    ExecJob.CommandType = CommandType.StoredProcedure;
    ExecJob.CommandText = "msdb.dbo.sp_update_schedule";
    ExecJob.Parameters.AddWithValue("@name", "a");
    ExecJob.Parameters.AddWithValue("@new_name", " b");                    
    ExecJob.Connection = MyConnection;
    

    执行此SQL时会导致此错误 Supply either @schedule_id or @name to identify the schedule. 有人能帮我吗?我真的不太熟悉sql。

    1 回复  |  直到 7 年前
        1
  •  0
  •   Dan Guzman    7 年前

    尝试使用ODBC转义语法,传递位置参数:

    OdbcCommand ExecJob = new OdbcCommand();           
    ExecJob.CommandType = CommandType.StoredProcedure;
    ExecJob.CommandText = "call msdb.dbo.sp_update_schedule(?,?,?)";
    ExecJob.Parameters.AddWithValue("@schedule_id", Dbnull.Value);
    ExecJob.Parameters.AddWithValue("@name", "a");
    ExecJob.Parameters.AddWithValue("@new_name", "b");                    
    ExecJob.Connection = MyConnection;
    
    推荐文章