Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/320.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将复选框值传递给SQL Server存储过程_C#_Sql Server_Winforms_Stored Procedures_Datagridviewcheckboxcell - Fatal编程技术网

C# 将复选框值传递给SQL Server存储过程

C# 将复选框值传递给SQL Server存储过程,c#,sql-server,winforms,stored-procedures,datagridviewcheckboxcell,C#,Sql Server,Winforms,Stored Procedures,Datagridviewcheckboxcell,我正在Winforms上使用C#从库中的类填充datagridview。我已经能够使用存储过程让datagridview填充我的所有SQL Server数据 我希望允许最终用户修改datagridview中的单元格,这将通过第二个存储过程更新SQL Server表。但是,调用更新过程后,我似乎无法识别复选框值 我的更新查询如下: public void UpdateEmployee(int empID, string initials, string firstName, string last

我正在Winforms上使用C#从库中的类填充datagridview。我已经能够使用存储过程让datagridview填充我的所有SQL Server数据

我希望允许最终用户修改datagridview中的单元格,这将通过第二个存储过程更新SQL Server表。但是,调用更新过程后,我似乎无法识别复选框值

我的更新查询如下:

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();
        }
    }
}
创建library类的实例后,我尝试使用以下代码行调用
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);

拼写错误?主动的而不是主动的

这确实消除了错误,但更新不起作用:(非常感谢您看到这一点!我不敢相信我以前没有看到这一点。我现在可以工作了!感谢大家的快速回复!我最终从CellEndEdit事件调用了更新方法。:0)您收到错误是因为拼写错误
@Active
。但更重要的是,@Siyual我同意,但在这种情况下,这应该不是什么大问题。参数中指定了数据类型,因为它们使用的是存储过程。使用AddWithValue()是否有缺点?@Siyual-请随时向我发送指向AddWithValue()替代方案网站的链接。“我刚学过这种方法,我欢迎更好的方法。”Wurm在我第一篇评论中的链接解释了失败和替代方案。