I am using C# on Winforms to populate a datagridview from a class in a library. I have been able to get the datagridview to populate with all of my SQL Server data using a stored procedure.
I wish to allow the end user to modify the cells in the datagridview, which will update the SQL Server table through a second stored procedure. However, I cannot seem to get the checkbox value to be recognized once the update procedure is called.
My update query is as follows:
public void UpdateEmployee(int empID, string initials, string firstName, string lastName, int active)
{
using (SqlConnection conn = new SqlConnection(DatabaseConnection.Database))
{
conn.Open();
using (SqlCommand cmd = conn.CreateCommand())
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "UpdateEmployee";
cmd.Parameters.AddWithValue("@EmpID", empID);
cmd.Parameters.AddWithValue("@Initials", initials);
cmd.Parameters.AddWithValue("@FirstName", firstName);
cmd.Parameters.AddWithValue("@LastName", lastName);
cmd.Parameters.AddWithValue("@Acvite", active);
cmd.ExecuteNonQuery();
}
}
}
After creating an instance of the library class, I was trying to call the Update
method with this line of code:
empData.UpdateEmployee(Convert.ToInt32(dataGridView1[0, e.RowIndex].Value), // EmpID
dataGridView1[1, e.RowIndex].Value.ToString(), //Initials
dataGridView1[2, e.RowIndex].Value.ToString(), //FirstName
dataGridView1[3, e.RowIndex].Value.ToString(), //LastName
Convert.ToInt16(dataGridView1[4, e.RowIndex].EditedFormattedValue)); // Active checkbox
I am getting an error stating that @Active
has not been provided.
Can anyone help me resolve this issue?
cmd.Parameters.AddWithValue("@Acvite", active);
Spelling error? Active not Acvite?