Aktham Mahmoud

Aktham Mahmoud

  • NA
  • 720
  • 37.5k

Why stored procedure not working by button

Sep 11 2020 6:03 PM
Greeting
 
I created a button,  when an Admin click on it call stored procedure to do this step:
===> Modify Column value [Bit] from true to False when a records came old than 30 days.
What happen?
when I click on button a page refresh, but a rows in table not modfiy ( change column value)
 
Button code:
  1. protected void SChJ_Click(object sender, EventArgs e)    
  2. {    
  3.     string connectionString = @"Data Source=(local)\SQLEXPRESS;AttachDbFilename=|DataDirectory|\land.mdf;Integrated Security=True";    
  4.     using (SqlConnection sqlcon = new SqlConnection(connectionString))    
  5.     {    
  6.         try    
  7.         {    
  8.             sqlcon.Open();    
  9.             SqlCommand sqlcmd = new SqlCommand("get_expir_job_date", sqlcon);    
  10.             sqlcmd.CommandType = CommandType.StoredProcedure;    
  11.             sqlcmd.Parameters.AddWithValue("@C_date", SqlDbType.DateTime);    
  12.             sqlcmd.Parameters.AddWithValue("@JEnable", SqlDbType.Bit);  
  13.             sqlcmd.ExecuteNonQuery();    
  14.             sqlcon.Close();    
  15.         }    
  16.         catch (Exception ex)    
  17.         {  
  18.             JobFaUp.Text = ex.ToString();    
  19.         }  
  20.     }  
  21. }  
Stored Procedure Code
  1. CREATE PROCEDURE [dbo].[get_expir_job_date]  
  2.     @C_date datetime,  //Create Date
  3.     @JEnable bit  //JOb Status Enable or Disable 
  4. AS  
  5. BEGIN  
  6. SELECT * FROM [Jobs]   
  7. Update [Jobs] SET @JEnable='False'  
  8. WHERE   
  9. @C_date  >  DATEADD(DAY, +30, CURRENT_TIMESTAMP)  
  10. End

Answers (4)