6
Answers

Update code message box

Ask a question
neesha herath

neesha herath

11y
1.1k
1

Hi

below code is an update code. In this message boxes are not working properly. When I click the update button it always display the "record has been updated" message box.

Please help me..

        private void ButtUpdate_Click(object sender, EventArgs e)

        {

              int x;

               da.UpdateCommand = new SqlCommand("UPDATE EWO_DETAILS SET CONTRACTOR_CODE = @ CONTRACTOR_CODE, START_DATE = @START_DATE, END_DATE = @END_DATE, CREATED_BY = @CREATED_BY , CREATED_DATE = @CREATED_DATE  WHERE EWO_NO = @EWO_NO", cs);

               da.UpdateCommand.Parameters.Add("@CONTRACTOR_CODE", SqlDbType.VarChar).Value = TxtContractorCode.Text;

               da.UpdateCommand.Parameters.Add("@EWO_SPEC", SqlDbType.VarChar).Value = TxtEwoSpec.Text;

               da.UpdateCommand.Parameters.Add("@CAT", SqlDbType.VarChar).Value = TxtJcat.Text;

               da.UpdateCommand.Parameters.Add("@MAIN", SqlDbType.VarChar).Value = TxtJmain.Text;

               da.UpdateCommand.Parameters.Add("@SPEC", SqlDbType.VarChar).Value = RTBSpec.Text;

               da.UpdateCommand.Parameters.Add("@SUB", SqlDbType.VarChar).Value = TxtSub.Text;

               da.UpdateCommand.Parameters.Add("@XTC", SqlDbType.VarChar).Value = TxtExtc.Text;

               da.UpdateCommand.Parameters.Add("@START_DATE", SqlDbType.VarChar).Value = StartDatePicker.Value.Date;

               da.UpdateCommand.Parameters.Add("@END_DATE", SqlDbType.VarChar).Value = EndDatePicker.Value.Date;

               da.UpdateCommand.Parameters.Add("@CREATED_BY", SqlDbType.VarChar).Value = TxtCreatedBy.Text;

               da.UpdateCommand.Parameters.Add("@CREATED_DATE", SqlDbType.VarChar).Value = CreatedDatePicker.Value.Date;

 

               da.UpdateCommand.Parameters.Add("@EWO_NO", SqlDbType.Int).Value = ds.Tables[0].Rows[bs.Position][0];

               cs.Open();

               try

               {

                   x = da.UpdateCommand.ExecuteNonQuery();

                   cs.Close();

                   if (x >= 1)

                   {

                       MessageBox.Show("Record has been Updated ");

                   }

                   else

                   {

                       MessageBox.Show("Record Already Updated ", "Error");

                   }

               }

               catch

               {

                   MessageBox.Show("Error on update please reloggin", "Information");

                   cs.Close();

               }

 

        }


Answers (6)