Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/278.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
我正在运行一个web应用程序,希望用C#代码更新我的SQL Server用户配置文件数据库,但无论我做什么,我都无法让它工作_C#_Asp.net_Sql Server - Fatal编程技术网

我正在运行一个web应用程序,希望用C#代码更新我的SQL Server用户配置文件数据库,但无论我做什么,我都无法让它工作

我正在运行一个web应用程序,希望用C#代码更新我的SQL Server用户配置文件数据库,但无论我做什么,我都无法让它工作,c#,asp.net,sql-server,C#,Asp.net,Sql Server,我正在尝试为一个网站创建一个MyAccount页面,我正在使用ASP.NET和Bootstrap,在后台为我们的对象运行html和C。我们正在使用SQL Server来运行我们的数据库,我在更新时遇到了很多麻烦。我正在使用一个测试用户配置文件,我让我的合作伙伴硬插入到系统中,因为我还没有编程帐户创建系统,只有登录 问题是,当我运行更新代码时,SQL Server数据库不会使用传递的信息进行更新。我没有收到任何异常,我知道我的连接字符串在我使用它登录并将数据库内容拖到主屏幕上的文本框中时起作用。正

我正在尝试为一个网站创建一个MyAccount页面,我正在使用ASP.NET和Bootstrap,在后台为我们的对象运行html和C。我们正在使用SQL Server来运行我们的数据库,我在更新时遇到了很多麻烦。我正在使用一个测试用户配置文件,我让我的合作伙伴硬插入到系统中,因为我还没有编程帐户创建系统,只有登录

问题是,当我运行更新代码时,SQL Server数据库不会使用传递的信息进行更新。我没有收到任何异常,我知道我的连接字符串在我使用它登录并将数据库内容拖到主屏幕上的文本框中时起作用。正因为如此,我不知道为什么它没有更新,我感到非常失落

我已经删除了连接字符串本身的部分,因为这个服务器不是我自己的,我不希望我教授的个人连接和登录凭据出现在互联网上

每次尝试更改项目上的状态变量时,运行查询的调试标签都会告诉我1行已生效

我试图更新的用户配置文件中存储了以下信息

Username: MarshallE  
Email: Test1234  
Password: Test1234!  
First Name: Marshall  
Last Name: Emmer  
Properties Rented: Prime Place  
Universities Attended Oklahoma State University  
State: N/A (My partner just added this and didn't update the profile)
这是我用来尝试和更新的代码:

protected void btnRegAcctUpdate_Click(object sender, EventArgs e)
{
    // This unit's job is to update the database of the specified user with the info in the text boxes
    // Make sure the password fields are the same
    if (txtAcctPass1.Text == txtAcctPass2.Text)
    {
        lblAcctDebug.Text = "";

        SqlConnection MyConnection = new SqlConnection();
        MyConnection.ConnectionString = "Server= (N/A ;Database=F19_groupRoss;User Id=groupRoss;Password = (N/A);";

        string MyUpdateStatement;
        MyUpdateStatement = "UPDATE dbo.UserID SET Email = @Email, Password = @Password, FirstName = @FirstName, LastName = @LastName, Universities = @University, Town = @Town, State = @State" + " WHERE UserID = @UserID";

        SqlCommand MySqlCmd = new SqlCommand(MyUpdateStatement, MyConnection);

        // These are the values we will be overriding the database with
        MySqlCmd.Parameters.AddWithValue("@UserID", (string)Session["UserID"]);
        MySqlCmd.Parameters.AddWithValue("@FirstName", txtAcctFirstName.Text);
        MySqlCmd.Parameters.AddWithValue("@LastName", txtAcctLastName.Text);
        MySqlCmd.Parameters.AddWithValue("@Email", txtAcctEmail.Text);
        MySqlCmd.Parameters.AddWithValue("@Password", txtAcctPass1.Text);
        MySqlCmd.Parameters.AddWithValue("@State", txtAcctState.Text);
        MySqlCmd.Parameters.AddWithValue("@Town", txtAcctTown.Text);
        MySqlCmd.Parameters.AddWithValue("@University", txtAcctUniversity.Text);

        // Open the connection
        MyConnection.Open();

        int rows = MySqlCmd.ExecuteNonQuery();
        lblDebug2.Text = "Rows affected: " + rows;

        MyConnection.Close();
    }
    else
    {
        lblAcctDebug.Text = "Error: Please ensure the text in the new password and password confirmation boxes are identical";
    }
}

如果有人能告诉我我做错了什么,我会非常感激

尝试添加如下参数:

MysqlCmd.Parameters.Add(New Parameter(@FirstName, txtAcctFirstName.text));

评论不用于扩展讨论;此对话已结束。您是否调试了代码?是否有任何异常?您是否能够在数据库上运行探查器以查看执行的具体内容?另外-您确定会话用户id正确吗?添加MySqlCmd.CommandType=CommandType.Text;并确保userID是正确的,对于测试,尝试硬编码该值并验证它。