为什么我的表数据库中只更新了一列?

时间:2016-01-21 05:00:19

标签: c#

我正在更新MyAccount但是只更新了一列[密码]。以下是我的代码。请帮助谢谢。

private string connstr =
        System.Web.Configuration.WebConfigurationManager.ConnectionStrings
        ["ConnectionString"].ConnectionString;
private SqlConnection conn;
private SqlCommand cmd;

conn = new SqlConnection(connstr);
cmd = new SqlCommand("Update AdminUsers Set Name=@Name, UserName=@UserName,  
                      Address=@Address, Phone=@Phone, Email=@Email, Password=@Password
                     Where AdminUserID=@AdminUserID", conn);

    cmd.Parameters.AddWithValue("@AdminUserID", lblAdminMyAcctID.Text);
    cmd.Parameters.AddWithValue("@Name", txtAdminMyAcctName.Text);
    cmd.Parameters.AddWithValue("@UserName", txtAdminMyAcctUserName.Text);
    cmd.Parameters.AddWithValue("@Address", txtAdminMyAcctAddress.Text);
    cmd.Parameters.AddWithValue("@Phone", txtAdminMyAcctPhone.Text);
    cmd.Parameters.AddWithValue("@Email", txtAdminMyAcctEmail.Text);
    cmd.Parameters.AddWithValue("@Password", txtAdminMyAcctNewPassword.Text);

conn.Open();
if (cmd.ExecuteNonQuery() == 1)
{

}
conn.Close();

Here are my Data at my Database

ID  Name    UserName    Address     Phone            Email                 UserType Branch      Status  Password
4   Default Admin       Auckland    64 123 45678910  admin@admin.com        Admin       Main        True    admin
6   Groomer Groomer2    Main        0221210801       groomer2@groomer.com   Groomer     Glen Ines   True    groomer3
7   Groomer Groomer1    Main        0221210800       groomer1@groomer.com   Groomer     Duniden     True    groomer1

我的数据库有什么问题吗?

1 个答案:

答案 0 :(得分:0)

您可以向我们提供有关表格结构的更多信息吗?我可以想到列的大小写,您使用数据库的操作系统是什么?

根据我的经验,在Linux中,我们应该注意到大写和小写都会影响代码,而在Windows上则不会(通常我会用大写代码编写)

编辑:

不应该是=

cmd = new SqlCommand("Update AdminUsers Set Name=@Name, UserName=@UserName,  
                  Address=@Address, Phone=@Phone, Email=@Email, Password=@Password
                 Where ID=@AdminUserID", conn);

我没有看到任何AdminUserID列