Update is not working

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • preeti13
    New Member
    • Aug 2007
    • 67

    Update is not working

    i am tring to update the records it is not giving me any error going through the appilication but it is not updating the data base i am not able to find the problem if any one know about this then please help me
    my cod eis like this:
    Code:
    private void cmdbutton_Click(object sender, System.EventArgs e)
    		{
    			
          
    			HtmlInputHidden objHid;
    			HtmlInputHidden objHidden; 
    			HtmlInputRadioButton rdoButton; 
    			DataGridItem item; 
    			for (int counter = 0; counter <= this.gvEmployee.Items.Count - 1; counter++) 
    			{ 
    				item = gvEmployee.Items[counter]; 
    				rdoButton = ((HtmlInputRadioButton)(item.FindControl("rdoEmployeeNominationID"))); 
    				objHidden = ((HtmlInputHidden)(item.FindControl("hidEmployeeNominationID"))); 
                   objHid = ((HtmlInputHidden)(item.FindControl("hidDatecreated"))); 
    				if (!(rdoButton == null & !(objHidden == null)& !(objHid==null))) 
    				{ 
    //					if (rdoButton.Checked == true) 
    //					{ 
    //						Response.Write(objHidden.Value); 
    //						Response.Write("This is the Employee Of the Month");
    //						return; 
    				
    					if (rdoButton.Checked == true) 
    					{ 
    						
    					
    
    string employee=objHidden.Value;
    
    		
    						SqlConnection oConn = new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["oConn"]); 
    			
    						SqlCommand objCmd = new SqlCommand("up_updateEmployeeNominations",oConn);
    						objCmd.CommandType = CommandType.StoredProcedure;
    						objCmd.Parameters.Add(new SqlParameter("@employeenominationid",employee));
    						SqlParameter datecreated = new SqlParameter("@datecreated", SqlDbType.DateTime); 
    						datecreated.Direction = ParameterDirection.Output; 
    						objCmd.Parameters.Add(datecreated);
     
    						oConn.Open();
    						objCmd.ExecuteNonQuery();
    						oConn.Close();
    
    
    					this.lblMassage.Text="This is Employee of the Month";
    					}
    
    		}
    				
    				
    	} 
    }

    and the store procedure is like this
    Code:
    CREATE  PROCEDURE [dbo].[up_updateEmployeeNominations]
    (
     
     @EmployeeNominationID int,
    @datecreated datetime output --varcahr(50)
    
    )
    as
    
    
    update  Reason 
    set    EmployeeSelected='1'
    from reason
    
    where
    reason.EmployeeNominationID=@EmployeeNominationID and  
    reason.datecreated =@datecreated 
    
     Set @datecreated =@datecreated
    GO
  • dotneto
    New Member
    • Feb 2007
    • 36

    #2
    Sorry, I'm maybe not understanding but i'll guess, maybe
    reason.datecrea ted =@datecreated is what makes it doesn't updates, because you are not passing any meaningful value to this parameter. Is an output parameter and it doesn't seem to be initialized. Maybe it makes that the updates never happens.


    Hope it helps.

    Comment

    • preeti13
      New Member
      • Aug 2007
      • 67

      #3
      Hey i tried that way but it did not work i think the problem is in the application because appication is not picking the vaule of the date created i am not able to find the probelm please help me with this
      Code:
      private void cmdbutton_Click(object sender, System.EventArgs e)
      		{
      			
            
      			
      			HtmlInputHidden objHidden; 
      			HtmlInputRadioButton rdoButton; 
      			DataGridItem item; 
      			for (int counter = 0; counter <= this.gvEmployee.Items.Count - 1; counter++) 
      			{ 
      				item = gvEmployee.Items[counter]; 
      				rdoButton = ((HtmlInputRadioButton)(item.FindControl("rdoEmployeeNominationID"))); 
      				objHidden = ((HtmlInputHidden)(item.FindControl("hidEmployeeNominationID"))); 
                   
      				if (!(rdoButton == null & !(objHidden == null))) 
      				{ 
      //					if (rdoButton.Checked == true) 
      //					{ 
      //						Response.Write(objHidden.Value); 
      //						Response.Write("This is the Employee Of the Month");
      //						return; 
      				
      					if (rdoButton.Checked == true) 
      					{ 
      						
      						string employee=objHidden.Value;
      
      
      		
      						SqlConnection oConn = new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["oConn"]); 
      			
      						SqlCommand objCmd = new SqlCommand("up_updateEmployeeNominations",oConn);
      						objCmd.CommandType = CommandType.StoredProcedure;
      						objCmd.Parameters.Add(new SqlParameter("@employeenominationid",employee));
      						SqlParameter datecreated = new SqlParameter("@datecreated", SqlDbType.DateTime); 
      						datecreated.Direction = ParameterDirection.Output; 
      						objCmd.Parameters.Add(datecreated);
       
      						oConn.Open();
      						objCmd.ExecuteNonQuery();
      						oConn.Close();
      
      
      					this.lblMassage.Text="This is Employee of the Month";
      					}
      
      		}
      				
      				
      	} 
      }

      Comment

      • dotneto
        New Member
        • Feb 2007
        • 36

        #4
        OK, have you checked that the record with this data exists:
        Code:
        where
        reason.EmployeeNominationID=@EmployeeNominationID and  
        reason.datecreated =@datecreated
        because I don't see why you compare with the @datecreated parameter, I think that parameter doesn't have any value and that makes that the update never happens.
        Is employee nomination Id a unique value?, if so, try this part:
        Code:
        where
        reason.EmployeeNominationID=@EmployeeNominationID
        with out this:
        Code:
        and  reason.datecreated =@datecreated
        [/CODE].

        Try that and let's see how it goes. if not, then whe can look something else.

        Comment

        • preeti13
          New Member
          • Aug 2007
          • 67

          #5
          thanks very much to halping me but this is not a solution either because. i have one to many relationship into the data base i means each record has a uniqe id value but it is nominated mre then one time like id number 1 has a 5 times in there but any ways i got the solution i have a reason id uniqe in there so i am dispalying the data using the reason id. once again thanks very much for helping me with this problem .

          Comment

          • dotneto
            New Member
            • Feb 2007
            • 36

            #6
            Originally posted by preeti13
            thanks very much to halping me but this is not a solution either because. i have one to many relationship into the data base i means each record has a uniqe id value but it is nominated mre then one time like id number 1 has a 5 times in there but any ways i got the solution i have a reason id uniqe in there so i am dispalying the data using the reason id. once again thanks very much for helping me with this problem .
            i'm glad you found the solution
            bye.

            Comment

            Working...