Click here to Skip to main content
15,888,286 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
My 3 tier application has a gridview with rowupdating event. I am passing a method to DAL for my row update in gridview.

Everything is working fine, values are getting updated in the sql table. But, On success, the value which is returned back is either 3 or 4, why is it happening? I am confused! I need the reason for this.

Here is my Rowupdating event.

protected void gvTask_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        int EID = Convert.ToInt32(gvTask.DataKeys[e.RowIndex].Value.ToString());
        string username = gvTask.DataKeys[e.RowIndex].Values["Username"].ToString();
        TextBox txtProjectName = (TextBox)gvTask.Rows[e.RowIndex].FindControl("txtProjectName");
        TextBox txtClientName = (TextBox)gvTask.Rows[e.RowIndex].FindControl("txtClientName");
        TextBox txtStatus = (TextBox)gvTask.Rows[e.RowIndex].FindControl("txtStatus");
        TextBox txtStartDate = (TextBox)gvTask.Rows[e.RowIndex].FindControl("txtStartDate");
        TextBox txtEndDate = (TextBox)gvTask.Rows[e.RowIndex].FindControl("txtEndDate");
        TextBox txtReportingManager = (TextBox)gvTask.Rows[e.RowIndex].FindControl("txtReportingManager");
        TextBox txtComments = (TextBox)gvTask.Rows[e.RowIndex].FindControl("txtComments");

        int updateInfo = objTABAL.UpdateTaskAsignmentDetailsBAL(EID,username,txtProjectName.Text,txtClientName.Text,txtStatus.Text,txtStartDate.Text,txtEndDate.Text,txtReportingManager.Text,txtComments.Text);
        if (updateInfo == 3) //heres where i am facing a problem.
        {
            lblresult.ForeColor = Color.Green;
            lblresult.Text = username + " Details Updated successfully";
            gvTask.EditIndex = -1;
            BindEmployeeDetails();
        }
    }


next follows my DAL class method.

public int UpdateTaskAsignmentDetailsDAL(int EID, string username, string ProjectName, string ClientName, string Status, string StartDate, string EndDate, string ReportingManager,string comments)
   {
       int ReturnValue=0;
       try
       {
           con = new SqlConnection(ConfigurationManager.ConnectionStrings["conn"].ConnectionString);
           con.Open();
           SqlCommand cmd = new SqlCommand("spUpdateTaskAssignment", con);
           cmd.CommandType = CommandType.StoredProcedure;
           cmd.Parameters.Add("@EID", EID);
           cmd.Parameters.Add("@ProjectName", ProjectName);
           cmd.Parameters.Add("@ClientName", ClientName);
           cmd.Parameters.Add("@Status", Status);
           cmd.Parameters.Add("@StartDate", StartDate);
           cmd.Parameters.Add("@EndDate", EndDate);
           cmd.Parameters.Add("@ReportingManager", ReportingManager);
           cmd.Parameters.Add("@Comments", comments);
           ReturnValue= cmd.ExecuteNonQuery();
       }
       catch (Exception ex)
       {
           //WebMsgBox.Show(ex.Message);
       }
       finally
       {
           con.Close();
           con.Dispose();
       }
       return ReturnValue;
   }


please help me out and if possible explain the situation, why it returns 3.

Thanks
Posted
Comments
Shahin Khorshidnia 16-Jun-13 6:14am    
Why don't you check 'spUpdateTaskAssignment' in SQL SERVER? Says it's updating 3 rows or 4
nawabprince 17-Jun-13 4:22am    
Please write here your store procedure code
spUpdateTaskAssignment

So we can see more detail about it.

Thanks
Prince Sharma

Refer - [MSDN] SqlCommand.ExecuteNonQuery Method[^]
Quote:
Return Value
Type: System.Int32
The number of rows affected.

As you have written the below line...
C#
ReturnValue= cmd.ExecuteNonQuery();

So, it is returning you the number of Rows Affected by the query, which you are getting as 3 or 4.
That means 3 or 4 rows are getting updated with the query.
 
Share this answer
 
There May Be Trigger In Your Table (Stored Procedure : spUpdateTaskAssignment).

ExecuteNonQuery Returns : Sum Of Total Number Of Rows Affected
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900