更新时间:2023-02-08 17:26:24
尝试使用此
try this
//Include Header File
Using System.Data.SqlClient;
//Declare
SqlConnection Con;
SqlCommand Cmd;
Con = new SqlConnection("ConnectionString");
Con.Open();
Cmd = new SqlCommand("Update TableName set Password=@Password where Id= 1",Con);
cmd.parameters.AddwithValue("@Password",TextBox1.text);
Cmd.ExecuteNoQuery();
Con.Close()
尝试:
string command ="UPDATE password SET main_password ='"+ TextBox.Text +"' WHERE id = 1"
顺便说一句,这是对您所做错误的更正.因此,我建议您使用参数化查询来避免问题和SQL注入.
BTW, this was the correction of what you were doing wrong. As such, I would suggest you to use parametrized query to avoid issues and SQL injection.
从
更改sql字符串
Change sql string from
string command ="UPDATE password SET main_password = TextBox.Text WHERE id = 1"
致
To
string command ="UPDATE password SET main_password = ''" + TextBox.Text + "'' WHERE id = 1"
但是使用SqlParameter更好.
But it is way better to use SqlParameter.