By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,620 Members | 1,512 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,620 IT Pros & Developers. It's quick & easy.

Update is not working

P: 67
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:
Expand|Select|Wrap|Line Numbers
  1. private void cmdbutton_Click(object sender, System.EventArgs e)
  2.         {
  3.  
  4.  
  5.             HtmlInputHidden objHid;
  6.             HtmlInputHidden objHidden; 
  7.             HtmlInputRadioButton rdoButton; 
  8.             DataGridItem item; 
  9.             for (int counter = 0; counter <= this.gvEmployee.Items.Count - 1; counter++) 
  10.             { 
  11.                 item = gvEmployee.Items[counter]; 
  12.                 rdoButton = ((HtmlInputRadioButton)(item.FindControl("rdoEmployeeNominationID"))); 
  13.                 objHidden = ((HtmlInputHidden)(item.FindControl("hidEmployeeNominationID"))); 
  14.                objHid = ((HtmlInputHidden)(item.FindControl("hidDatecreated"))); 
  15.                 if (!(rdoButton == null & !(objHidden == null)& !(objHid==null))) 
  16.                 { 
  17. //                    if (rdoButton.Checked == true) 
  18. //                    { 
  19. //                        Response.Write(objHidden.Value); 
  20. //                        Response.Write("This is the Employee Of the Month");
  21. //                        return; 
  22.  
  23.                     if (rdoButton.Checked == true) 
  24.                     { 
  25.  
  26.  
  27.  
  28. string employee=objHidden.Value;
  29.  
  30.  
  31.                         SqlConnection oConn = new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["oConn"]); 
  32.  
  33.                         SqlCommand objCmd = new SqlCommand("up_updateEmployeeNominations",oConn);
  34.                         objCmd.CommandType = CommandType.StoredProcedure;
  35.                         objCmd.Parameters.Add(new SqlParameter("@employeenominationid",employee));
  36.                         SqlParameter datecreated = new SqlParameter("@datecreated", SqlDbType.DateTime); 
  37.                         datecreated.Direction = ParameterDirection.Output; 
  38.                         objCmd.Parameters.Add(datecreated);
  39.  
  40.                         oConn.Open();
  41.                         objCmd.ExecuteNonQuery();
  42.                         oConn.Close();
  43.  
  44.  
  45.                     this.lblMassage.Text="This is Employee of the Month";
  46.                     }
  47.  
  48.         }
  49.  
  50.  
  51.     } 
  52.  
  53.  
  54.  

and the store procedure is like this
Expand|Select|Wrap|Line Numbers
  1. CREATE  PROCEDURE [dbo].[up_updateEmployeeNominations]
  2. (
  3.  
  4.  @EmployeeNominationID int,
  5. @datecreated datetime output --varcahr(50)
  6.  
  7. )
  8. as
  9.  
  10.  
  11. update  Reason 
  12. set    EmployeeSelected='1'
  13. from reason
  14.  
  15. where
  16. reason.EmployeeNominationID=@EmployeeNominationID and  
  17. reason.datecreated =@datecreated 
  18.  
  19.  Set @datecreated =@datecreated
  20. GO
  21.  
  22.  
Sep 13 '07 #1
Share this Question
Share on Google+
5 Replies


dotneto
P: 36
Sorry, I'm maybe not understanding but i'll guess, maybe
reason.datecreated =@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.
Sep 13 '07 #2

P: 67
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
Expand|Select|Wrap|Line Numbers
  1. private void cmdbutton_Click(object sender, System.EventArgs e)
  2.         {
  3.  
  4.  
  5.  
  6.             HtmlInputHidden objHidden; 
  7.             HtmlInputRadioButton rdoButton; 
  8.             DataGridItem item; 
  9.             for (int counter = 0; counter <= this.gvEmployee.Items.Count - 1; counter++) 
  10.             { 
  11.                 item = gvEmployee.Items[counter]; 
  12.                 rdoButton = ((HtmlInputRadioButton)(item.FindControl("rdoEmployeeNominationID"))); 
  13.                 objHidden = ((HtmlInputHidden)(item.FindControl("hidEmployeeNominationID"))); 
  14.  
  15.                 if (!(rdoButton == null & !(objHidden == null))) 
  16.                 { 
  17. //                    if (rdoButton.Checked == true) 
  18. //                    { 
  19. //                        Response.Write(objHidden.Value); 
  20. //                        Response.Write("This is the Employee Of the Month");
  21. //                        return; 
  22.  
  23.                     if (rdoButton.Checked == true) 
  24.                     { 
  25.  
  26.                         string employee=objHidden.Value;
  27.  
  28.  
  29.  
  30.                         SqlConnection oConn = new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["oConn"]); 
  31.  
  32.                         SqlCommand objCmd = new SqlCommand("up_updateEmployeeNominations",oConn);
  33.                         objCmd.CommandType = CommandType.StoredProcedure;
  34.                         objCmd.Parameters.Add(new SqlParameter("@employeenominationid",employee));
  35.                         SqlParameter datecreated = new SqlParameter("@datecreated", SqlDbType.DateTime); 
  36.                         datecreated.Direction = ParameterDirection.Output; 
  37.                         objCmd.Parameters.Add(datecreated);
  38.  
  39.                         oConn.Open();
  40.                         objCmd.ExecuteNonQuery();
  41.                         oConn.Close();
  42.  
  43.  
  44.                     this.lblMassage.Text="This is Employee of the Month";
  45.                     }
  46.  
  47.         }
  48.  
  49.  
  50.     } 
  51.  
  52.  
Sep 13 '07 #3

dotneto
P: 36
OK, have you checked that the record with this data exists:
Expand|Select|Wrap|Line Numbers
  1. where
  2. reason.EmployeeNominationID=@EmployeeNominationID and  
  3. 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:
Expand|Select|Wrap|Line Numbers
  1. where
  2. reason.EmployeeNominationID=@EmployeeNominationID 
with out this:
Expand|Select|Wrap|Line Numbers
  1. and  reason.datecreated =@datecreated 
[/code].

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

P: 67
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 .
Sep 14 '07 #5

dotneto
P: 36
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.
Sep 17 '07 #6

Post your reply

Sign in to post your reply or Sign up for a free account.