SQL 更新语句

本文关键字:语句 更新 SQL | 更新日期: 2023-09-27 18:32:36

我需要有关SQL连接的帮助。我有这个代码:

                        SqlConnection myConnection2 = new SqlConnection("server=c1212''SQLEXPRESS;" +
         "Trusted_Connection=yes;" +
         "database=SPZ; " +
         "connection timeout=30");
        try
        {
            myConnection2.Open();
            SqlCommand myCommand2 = new SqlCommand();
              myCommand2.CommandText = "UPDATE SPZ set Datum='" + textBox1.Text+"' , ČasP='"+textBox5.Text+"', ČasO='"+textBox6.Text+"', SPZ='"+textBox2.Text+"', Příjmení='"+textBox3.Text+"', Firma='"+textBox4.Text+"', Poznámka='"+textBox7.Text+"', Kontrola='"+textBox8.Text+ "' 
                where Datum='" + textBox9.Text + "' and ČasP='" + textBox13.Text + "' and ČasO='" + textBox14.Text + "' and SPZ='" + textBox10.Text + "' and Příjmení='" + textBox11.Text + "' and Firma='" + textBox12.Text + "' and Poznámka='" + textBox15.Text + "' and Kontrola='" + textBox16.Text + "'";

            myCommand2.ExecuteNonQuery();
          //  myConnection.Close();
        }
        catch (SqlException ex)
        {
            MessageBox.Show("Připojení do databáze selhalo! " + ex.Message);
        }

找不到问题所在,有人可以帮助我吗?

SQL 更新语句

必须在命令对象上设置连接。

myCommand2.Connection = myConnection2;