Priyanka Singh

Priyanka Singh

  • 651
  • 1.4k
  • 622k

While Updating gridview data,it shows an error.

Apr 19 2019 1:47 AM
  1. {  
  2.           int id = (int)gvEmployee.DataKeys[row.RowIndex].Value;  
  3.           String firstName = ((TextBox)row.Cells[0].Controls[0]).Text;  
  4.           String lastName = ((TextBox)row.Cells[0].Controls[0]).Text;  
  5.           String position = ((TextBox)row.Cells[0].Controls[0]).Text;  
  6.           String team = ((TextBox)row.Cells[0].Controls[0]).Text;  
  7.           if ((firstName ?? lastName ?? position ?? team) != String.Empty)  
  8.           {  
  9.               using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["DBConnectionString"].ConnectionString))  
  10.               {  
  11.                   string sql = @"update set employee set SET FirstName = @FirstName,LastName = @LastName,Position = @Position,Team = @Team WHERE Id = @Id";  
  12.                   using (SqlCommand cmd = new SqlCommand(sql, con))  
  13.                   {  
  14.                       con.Open();  
  15.                       cmd.Parameters.AddWithValue("@FirstName", firstName);  
  16.                       cmd.Parameters.AddWithValue("@LastName", lastName);  
  17.                       cmd.Parameters.AddWithValue("@Position", position);  
  18.                       cmd.Parameters.AddWithValue("@Team", team);  
  19.                       cmd.Parameters.AddWithValue("@ID", id);  
  20.                       cmd.ExecuteNonQuery();  
  21.                   }  
  22.   
  23.               }  
  24.               return true;  
  25.           }  
  26.           return false;  
  27.       }
 
It shows an error.Help me to resolve the problem.

Answers (4)