C# 应为参数'@id';,没有提供。id是主键和标识

C# 应为参数'@id';,没有提供。id是主键和标识,c#,sql-server,C#,Sql Server,我得到这个错误: 需要未提供的参数'@id'。id是主键和标识 我的代码: namespace se_up_de_in { public partial class Form1 : Form { SqlConnection conn = new SqlConnection(@"Data Source=DESKTOP-R0N4ID3;Initial Catalog=DBTask2;Integrated Security=True"); SqlCom

我得到这个错误:

需要未提供的参数'@id'。id是主键和标识

我的代码:

namespace se_up_de_in
{
    public partial class Form1 : Form
    {
        SqlConnection conn = new SqlConnection(@"Data Source=DESKTOP-R0N4ID3;Initial Catalog=DBTask2;Integrated Security=True");

        SqlCommand comm;
        SqlDataAdapter Adapter;

        DataTable Table = new DataTable();

        private void button2_Click(object sender, EventArgs e)
        {
            using (comm = new SqlCommand("proc_insertid", conn))
            {
                comm.CommandType = CommandType.StoredProcedure;
                conn.Open();

                SqlParameter[] parameter = new SqlParameter[5];
                parameter[0] = new SqlParameter("@id", SqlDbType.Int);
                parameter[0].Value = textBox5.Text;

                parameter[1] = new SqlParameter("@username", SqlDbType.NChar);
                parameter[1].Value = textBox1.Text;

                parameter[2] = new SqlParameter("@password", SqlDbType.NChar);
                parameter[2].Value = textBox2.Text;


                parameter[3] = new SqlParameter("@email", SqlDbType.NVarChar);
                parameter[3].Value = textBox3.Text;


                parameter[4] = new SqlParameter("@Type", SqlDbType.NChar);
                parameter[4].Value = textBox4.Text;

                comm.ExecuteNonQuery();

                comm.Parameters.AddRange(parameter);

                conn.Close();

                dataGridviewfill();
            }
        }

        private void button4_Click(object sender, EventArgs e)
        {
            using (comm = new SqlCommand("proc_Dlelete", conn))
            {
                comm.CommandType = CommandType.StoredProcedure;
                conn.Open();

                SqlParameter param = new SqlParameter();
                param = new SqlParameter("@id", SqlDbType.NChar);
                param.Value = textBox5.Text;

                comm.ExecuteNonQuery();
                comm.Parameters.Add(param);

                conn.Close();

                dataGridviewfill();
            }
        }
    }
}
我的存储过程:

CREATE PROCEDURE proc_insert
     (@id INT,
      @username NCHAR(10),
      @password NCHAR(10),
      @email NVARCHAR(MAX),
      @Type NCHAR(10))
AS
BEGIN
    INSERT INTO ttask2 (id, username, password, email, Type)
    VALUES (@id, @username, @password, @email, @Type)
END
颠倒这些;您需要在执行命令之前添加参数

comm.Parameters.AddRange(parameter);
comm.ExecuteNonQuery();

(与使用命令/参数的其他位置相同)

询问问题0需要未提供的参数'@id'。id是主键和标识在执行语句之前,您是否应该添加参数?请尝试为我们提供更多的上下文,并向我们解释您的目标。仅仅抛出代码和错误消息不足以帮助您或将来可能遇到相同问题的其他人。
comm.Parameters.AddRange(parameter);
comm.ExecuteNonQuery();