sql简单更新语句不起作用

拉祖·拉兹万(Lazu Razvan)

更新根本不起作用,行保持不变。我没有错误。有人知道为什么它不起作用吗?我想首先知道问题的原因,但是如果您有任何想法,关于如何改进我的代码的建议,我们将欢迎您。

 private void button2_Click(object sender, EventArgs e)
    {
        using (SqlConnection conn = new SqlConnection(@"Data Source=(LocalDB)\v11.0;AttachDbFilename=E:\C #\InsertDeleteUpdate-Login\InsertDeleteUpdate-Login\Database1.mdf;Integrated Security=True"))
        using (SqlCommand cmd = new SqlCommand("UPDATE info SET Password=@Password WHERE Id=@Id AND Password=@Password1",conn))
        {
            conn.Open();
            cmd.Parameters.AddWithValue("@Password", textBox4.Text);
            cmd.Parameters.AddWithValue("@Id", textBox3.Text);
            cmd.Parameters.AddWithValue("@Password1", textBox2.Text);
        }
    }
用户名

您需要执行查询

cmd.Parameters.AddWithValue("@Password", textBox4.Text);
cmd.Parameters.AddWithValue("@Id", textBox3.Text);
cmd.Parameters.AddWithValue("@Password1", textBox2.Text);

cmd.ExecuteNonQuery(); // this is what was missing

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章