SQL Server数据库:从texbox更改表值

xeL*_*xel 0 c# sql-server

我想更改SQL Server表中的列的值,由2个其他列过滤.但它返回错误:语法","不正确.这是代码:

private void button1_Click(object sender, EventArgs e)
{
        string connectionString = @"Data Source=" + System.IO.File.ReadAllText("Server.ini") + ";" + "Initial Catalog=" + "lin2world" + ";" + "User ID=" + System.IO.File.ReadAllText("User.ini") + ";" + "Password=" + System.IO.File.ReadAllText("Password.ini");

        string sql = "UPDATE user_item SET amount='" + textBox3.Text + "'WHERE char_id='" + textBox1.Text + "' ,item_type='" + textBox2.Text + "' ";

        SqlConnection connection = new SqlConnection(connectionString);
        SqlDataAdapter dataadapter = new SqlDataAdapter(sql, connection);

        DataSet ds = new DataSet();

        connection.Open();

        dataadapter.Fill(ds, "user_item");
        connection.Close();

        MessageBox.Show("Item Amount Changed");
    }
Run Code Online (Sandbox Code Playgroud)

谢谢!

Bar*_*chs 5

你以前错过了一个空间WHERE.

并且您有一个逗号,您想要使用它AND.

改变如下:

string sql = "UPDATE user_item SET amount='" + textBox3.Text + "' WHERE char_id='" + 
                        textBox1.Text + "' AND item_type='" + textBox2.Text + "' ";
Run Code Online (Sandbox Code Playgroud)