-2

C#パラメータに問題があります。

そして、私はこのエラーを受け取ります:

メソッド「ExecuteInsert」のオーバーロードは「5」を取りません

これは私のコードです:

private void ExecuteInsert(string FirstName, string LastName, string MiddleName, string UserName, string Password, string MemberStatus)
{
    SqlConnection conn = new SqlConnection(GetConnectionString());
    string sql = "INSERT INTO Registration (FirstName, LastName, MiddleName, UserName, Password, MemberStatus, DateRegistration) VALUES"
                + " (@FirstName,@LastName,@MiddleName,@UserName,@Password,'ACTIVE',CURRENT_TIMESTAMP)";

    try
    {
        conn.Open();
        SqlCommand cmd = new SqlCommand(sql, conn);
        SqlParameter[] param = new SqlParameter[5];
        param[0] = new SqlParameter("@FirstName", SqlDbType.VarChar, 50);
        param[1] = new SqlParameter("@LastName", SqlDbType.VarChar, 50);
        param[2] = new SqlParameter("@MiddleName", SqlDbType.VarChar, 50);
        param[3] = new SqlParameter("@UserName", SqlDbType.VarChar, 50);
        param[4] = new SqlParameter("@Password", SqlDbType.VarChar, 50);
        param[5] = new SqlParameter("ACTIVE", SqlDbType.VarChar, 50);
        param[6] = new SqlParameter("CURRENT_TIMESTAMP", SqlDbType.VarChar, 50);

        param[0].Value = FirstName;
        param[1].Value = LastName;
        param[2].Value = MiddleName;
        param[3].Value = UserName;
        param[4].Value = Password;
        param[5].Value = MemberStatus;
        param[6].Value = DateRegistration;

        for (int i = 0; i < param.Length; i++)
        {
            cmd.Parameters.Add(param[i]);
        }

        cmd.CommandType = CommandType.Text;
        cmd.ExecuteNonQuery();
    }
    catch (System.Data.SqlClient.SqlException ex)
    {
        string msg = "Insert Error:";
        msg += ex.Message;
        throw new Exception(msg);
    }
    finally
    {
        conn.Close();
    }
}

protected void Button1_Click(object sender, EventArgs e)
{
    if (TxtPassword.Text == TxtRePassword.Text)
    {
        //call the method to execute insert to the database
        ExecuteInsert(TxtFName.Text,
                      TxtLName.Text,
                      TxtMName.Text,
                      TxtUserName.Text,
                      TxtPassword.Text);
        Response.Write("Record was successfully added!");
        ClearControls(Page);
    }
    else
    {
        Response.Write("Password did not match");
        TxtPassword.Focus();
    }
}
public static void ClearControls(Control Parent)
{
    if (Parent is TextBox)
    { (Parent as TextBox).Text = string.Empty; }
    else
    {
        foreach (Control c in Parent.Controls)
            ClearControls(c);
    }
}
}
4

1 に答える 1

5

冗談ですか?string MemberStatusあなたのパラメータを数えてください、あなたが電話をかけるときにあなたが行方不明であることに注意してください。エラーはこれ以上明確にできませんでした

于 2013-02-01T02:44:05.847 に答える