-4

我无法更新数据库中的记录。

我的代码如下:

private void update_Click(object sender, EventArgs e)
{
        con.Open();

         try

         {
        string strQuery = "UPDATE test_name SET Test_Name = @name, Price = @price, Lab_Price = @lprice, normal_value_child = @child, normal_value_men = @men, normal_value_women = @women, notes = @note, unit = @un, SubGroup = @sub, MainGroup = @main" +
              "WHERE Test_Id = @tstID";
        using (System.Data.SqlServerCe.SqlCeCommand cmdSelect = new System.Data.SqlServerCe.SqlCeCommand(strQuery, con))
        {
            cmdSelect.Parameters.AddWithValue("@tstID", richTextBox2.Text);
            cmdSelect.Parameters.AddWithValue("@name", richTextBox1.Text);
            cmdSelect.Parameters.AddWithValue("@price", richTextBox7.Text);
            cmdSelect.Parameters.AddWithValue("@lprice", richTextBox8.Text);
            cmdSelect.Parameters.AddWithValue("@child", richTextBox5.Text);
            cmdSelect.Parameters.AddWithValue("@men", richTextBox4.Text);
            cmdSelect.Parameters.AddWithValue("@women", richTextBox3.Text);
            cmdSelect.Parameters.AddWithValue("@note", richTextBox9.Text);
            cmdSelect.Parameters.AddWithValue("@un", richTextBox6.Text);
            cmdSelect.Parameters.AddWithValue("@sub", comboBox2.Text);
            cmdSelect.Parameters.AddWithValue("@main", comboBox1.Text);
            cmdSelect.ExecuteNonQuery();
            updatedb();
            con.Close();
        }
    }
    catch (Exception ex)
    {

    }

    this.test_nameTableAdapter2.Fill(this.datalabDataSet14.test_name);

    MessageBox.Show("Updated Successfully");
}
}

我不明白有什么问题。

4

1 回答 1

2

在 WHERE 之前添加空格:

string strQuery = "UPDATE test_name SET Test_Name = @name, Price = @price, Lab_Price = @lprice, normal_value_child = @child, normal_value_men = @men, normal_value_women = @women, notes = @note, unit = @un, SubGroup = @sub, MainGroup = @main" +
          " WHERE Test_Id = @tstID";
于 2013-10-19T09:00:55.667 回答