Vignesh Kumar

Vignesh Kumar

  • NA
  • 1k
  • 404.7k

Add New Item in grid view not working

Oct 28 2013 3:03 AM
Hi,

I am using this below codes to add new items to the grid row and its not getting inserted. I don't know what mistake I done in the code. Can anyone correct me?

code behind(UI):
protected void ResultGridView_RowCommand(object sender, GridViewCommandEventArgs e)
  {
  if (e.CommandName.Equals("AddNew"))
  {
  TextBox EmpID = (TextBox)GridView1.FooterRow.FindControl("txtEmpID");
  TextBox Name = (TextBox)GridView1.FooterRow.FindControl("txtName");
  TextBox Designation = (TextBox)GridView1.FooterRow.FindControl("txtDesignation");
  TextBox City = (TextBox)GridView1.FooterRow.FindControl("txtCity");
  AppGridData.InsertGridValues(EmpID.Text, Name.Text, Designation.Text, City.Text);
  FillVendorGrid();
  }
  }

BLL:
 public static bool InsertGridValues(string EmpID, string Name, string Description, string City)
  {
  return AppGridRepository.InsertGridValues(EmpID, Name, Description, City);
  }

DAL:
public static bool InsertGridValues(string EmpID, string Name, string Description, string City)
  {
  string CS = ConfigurationManager.ConnectionStrings[Constants.ConnectionString].ConnectionString;
  using (SqlConnection connection = new SqlConnection(CS))
  {
  SqlCommand command = new SqlCommand();
  command.Connection = connection;
  command.CommandText = "INSERT INTO [AppInvent_Test]([EmpID],[Name],[Description],[City]) Values('" + EmpID + "','" + Name + "','" + Description + "', '" + City + "')";
  connection.Open();
  command.ExecuteNonQuery();
  }
  return true;
  }

Answers (10)