Aktham Mahmoud

Aktham Mahmoud

  • NA
  • 720
  • 37.5k

What's wrong in that stored procedure

Jun 27 2020 10:45 AM
Hi
I designed a stored procedure execute by aspx side to disable an old published jobs which have date expired by button click.
 
stored procedure code:
  1. CREATE PROCEDURE [dbo].[get_expir_job_date]  
  2.     @C_date datetime,  
  3.     @JEnable bit  
  4.   
  5.     -- NULL is the default value.  
  6. AS  
  7. BEGIN  
  8.     IF @C_date != Null  
  9.     BEGIN  
  10.        SELECT @C_date FROM [Jobs]   
  11.   
  12. if @C_date  > DATEADD(DAY, +30, CURRENT_TIMESTAMP)  
  13. exec get_expir_job_date 'UPDATE Jobs SET "@JEnable=False" ';  
  14.   
  15.     END  
  16.         RETURN     
  17. END  
C# button code: 
  1. protected void SChJ_Click(object sender, EventArgs e)  
  2. {  
  3.         string connectionString = @"Data Source=(local)\SQLEXPRESS;AttachDbFilename=|DataDirectory|\DbCh.mdf;Integrated Security=True";  
  4.         using (SqlConnection sqlcon = new SqlConnection(connectionString))  
  5.         {  
  6.             try  
  7.             {  
  8.                 SqlCommand sqlcmd = new SqlCommand("get_expir_job_date", sqlcon);  
  9.                 sqlcmd.CommandType = CommandType.StoredProcedure;  
  10.                 sqlcmd.Parameters.AddWithValue("@C_date", SqlDbType.DateTime);  
  11.                 sqlcmd.Parameters.AddWithValue("@JEnable", SqlDbType.Bit);  
  12.                 sqlcon.Open();  
  13.                 sqlcmd.ExecuteNonQuery();  
  14.                 sqlcon.Close();  
  15.             }  
  16.             catch (Exception ex)  
  17.             {  
  18.   
  19.                 JobFaUp.Text = ex.ToString();  
  20.             }  
  21.   
  22.         }  
  23. }  
Actually, nothing affects on rows.
 
So what's the wrong, I don't know?
 
Thanks

Answers (2)