如何使用新用户输入更新数据库中的列? [英] How do I update a column in database with the new user inputs?
本文介绍了如何使用新用户输入更新数据库中的列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
private void button1_Click(object sender, EventArgs e)
{
/*VirtualPet.Popup popup = new VirtualPet.Popup();
popup.UpdatePopup();*/
SqlCeConnection conn = new SqlCeConnection("Data Source=E:\\Project Final_Year\\Project Final\\MyProject\\ERU Implementation\\VirtualPetedit\\VirtualPet\\MyDB.sdf");
string query = "UPDATE Events SET (event_name='" + this.textBox2.Text + "', event_description='" + this.richTextBox1.Text + "', event_type='" + this.comboBox1.SelectedItem + "', date='" + this.dateTimePicker1.Value + "', time='" + this.textBox3.Text +"') WHERE event_id = " + textBox1.Text + ";";
SqlCeCommand cmd = new SqlCeCommand(query, conn);
try
{
conn.Open();
SqlCeCommand command = new SqlCeCommand(query, conn);
command.ExecuteNonQuery();
VirtualPet.Popup popup = new VirtualPet.Popup();
popup.UpdatePopup();
conn.Close();
//command.Parameters.AddWithValue("@EI", textBox4.Text);
}
catch (Exception err)
{
MessageBox.Show(err.Message);
}
}
推荐答案
您没有说出哪个数据库系统,但是(与INSERT语句不同) UPDATE语句不会在列和值周围使用括号。
You don't say which database system, but (unlike an INSERT statement) an UPDATE statement doesn't use parentheses around the columns and values.
更新语句不需要括号。为什么不尝试在数据库中创建一个存储过程,以便你不能先测试它然后调用前端的程序?
更新[table_name] set [Field_name ] = [Object] where [Field_name] = [value]
也只是一个抬头,尝试使用参数来避免sql注入。
Update statement doesn't need a parenthesis. Why not try creating a stored procedure in the database so that you cant test it first there then call the procedure in the front end?
Update [table_name] set [Field_name] = [Object] where [Field_name] = [value]
also just a heads up, try to use parameters to avoid sql injection.
这篇关于如何使用新用户输入更新数据库中的列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文