我的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);
}
我找不到有什么不对,有人可以帮帮我吗?
答案 0 :(得分:0)
您必须在命令对象上设置Connection。
myCommand2.Connection = myConnection2;