Priyanka Singh

Priyanka Singh

  • 690
  • 1.4k
  • 676k

Error in Updation of data in gridview.

Apr 22 2019 5:33 AM
    private bool UpdateEmployee(GridViewRow row)
        {
            int id = (int)gvEmployee.DataKeys[row.RowIndex].Value;
            String firstName = ((TextBox)row.Cells[0].Controls[0]).Text;
            String lastName = ((TextBox)row.Cells[0].Controls[0]).Text;
            String position = ((TextBox)row.Cells[0].Controls[0]).Text;
            String team = ((TextBox)row.Cells[0].Controls[0]).Text;
           
            if ((firstName ?? lastName ?? position ?? team) != String.Empty)
            {
                using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["DBConnectionString"].ConnectionString))
                {
                    string sql = @"update set employee set SET FirstName = @FirstName,LastName = @LastName,Position = @Position,Team = @Team WHERE Id = @Id";
                    using (SqlCommand cmd = new SqlCommand(sql, con))
                    {
                        con.Open();
                        cmd.Parameters.AddWithValue("@FirstName", firstName);
                        cmd.Parameters.AddWithValue("@LastName", lastName);
                        cmd.Parameters.AddWithValue("@Position", position);
                        cmd.Parameters.AddWithValue("@Team", team);
                        cmd.Parameters.AddWithValue("@id", id);
                        cmd.ExecuteNonQuery();
                    }

                }
                return true;
            }
            return false;
        }
 
 
 
I get this error while updation of data in gridview.
 

Answers (1)