我试图让我的更新功能起作用。我已经包含了txtPassword和txtConfirmPassword文本框。两个文本框必须匹配更新之前,但我得到这个错误:ExecuteNonQuery:CommandText属性尚未初始化
ExecuteNonQuery: CommandText property has not been initialized
我该如何使它工作?这里是我的代码:
protected void btnUpdateAccount_Click(object sender, EventArgs e)
{
con.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
if (txtPassword.Text == "")
{
cmd.CommandText = "UPDATE Users SET [email protected], [email protected], " +
"[email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected] " +
"WHERE [email protected]";
}
else
{
if (txtConfirmPassword != txtPassword)
{
pnlInconsistent.Visible = true;
}
else
{
cmd.CommandText = "UPDATE Users SET [email protected], [email protected], [email protected], " +
"[email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected] " +
"WHERE [email protected]";
}
cmd.Parameters.Add("@EmailAddress", SqlDbType.NVarChar).Value = txtEmail.Text;
cmd.Parameters.Add("@Password", SqlDbType.NVarChar).Value = Helper.CreateSHAHash(txtPassword.Text);
cmd.Parameters.Add("@FirstName", SqlDbType.VarChar).Value = txtFN.Text;
cmd.Parameters.Add("@LastName", SqlDbType.VarChar).Value = txtLN.Text;
//cmd.Parameters.Add("@Address", SqlDbType.NVarChar).Value = txtAddress.Text;
cmd.Parameters.Add("@Street", SqlDbType.NVarChar).Value = txtStreet.Text;
cmd.Parameters.Add("@Municipality", SqlDbType.NVarChar).Value = txtMunicipality.Text;
cmd.Parameters.Add("@City", SqlDbType.NVarChar).Value = txtCity.Text;
cmd.Parameters.Add("@ZipCode", SqlDbType.NVarChar).Value = txtZipCode.Text;
cmd.Parameters.Add("@ContactNo", SqlDbType.NVarChar).Value = txtContact.Text;
cmd.Parameters.Add("@UserID", SqlDbType.Int).Value = Session["UserID"].ToString();
if (fuImage.HasFile)
{
cmd.Parameters.Add("@Image", SqlDbType.Text).Value = "~/images/" + fuImage.FileName;
fuImage.SaveAs(Server.MapPath("~/images/" + fuImage.FileName));
}
else
{
cmd.Parameters.Add("@Image", SqlDbType.Text).Value = imgAvatar.ImageUrl;
}
if (txtPassword.Text != "")
{
cmd.Parameters.Add("@Password", SqlDbType.NVarChar).Value =
Helper.CreateSHAHash(txtPassword.Text);
}
cmd.ExecuteNonQuery();
con.Close();
GetProfileInfo();
pnlUpdated.Visible = true;
Helper.AddLog(Session["userid"].ToString(), "Update", "Updated Profile Information");
GetProfileInfo();
}
}