将复选框值传递给 SQL 服务器存储过程
Passing a checkbox value to a SQL Server stored procedure
我在 Winforms 上使用 C# 从库中的 class 填充数据网格视图。我已经能够使用存储过程让 datagridview 填充我的所有 SQL 服务器数据。
我希望允许最终用户修改 datagridview 中的单元格,这将通过第二个存储过程更新 SQL 服务器 table。但是,一旦调用更新过程,我似乎无法识别复选框值。
我的更新查询如下:
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();
}
}
}
创建库 class 的实例后,我试图用这行代码调用 Update
方法:
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
我收到一条错误消息,指出未提供 @Active
。
谁能帮我解决这个问题?
cmd.Parameters.AddWithValue("@Acvite", active);
拼写错误?主动不Acvite?
我在 Winforms 上使用 C# 从库中的 class 填充数据网格视图。我已经能够使用存储过程让 datagridview 填充我的所有 SQL 服务器数据。
我希望允许最终用户修改 datagridview 中的单元格,这将通过第二个存储过程更新 SQL 服务器 table。但是,一旦调用更新过程,我似乎无法识别复选框值。
我的更新查询如下:
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();
}
}
}
创建库 class 的实例后,我试图用这行代码调用 Update
方法:
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
我收到一条错误消息,指出未提供 @Active
。
谁能帮我解决这个问题?
cmd.Parameters.AddWithValue("@Acvite", active);
拼写错误?主动不Acvite?