1个回答
展开全部
一个例子,在按钮的单击事件的方法中写如下代码:
str_update = "insert into 报修管理(记录编号,报修物品,寝室编号,报修人,报修时间,报修原因) values("+bianhao+",'" + this.TextBox1.Text + "','" + this.TextBox2.Text + "','" + this.TextBox3.Text + "','" + this.TextBox4.Text + "','" + this.TextBox5.Text + "')";
try
{
myconnection.Open();
SqlCommand mycommand = new SqlCommand(str_update, myconnection);
mycommand.ExecuteNonQuery();
myconnection.Close();
return "数据更新完成!";
}
catch (Exception ex)
{ myconnection.Close(); return ex.Message.ToString(); }
str_update = "insert into 报修管理(记录编号,报修物品,寝室编号,报修人,报修时间,报修原因) values("+bianhao+",'" + this.TextBox1.Text + "','" + this.TextBox2.Text + "','" + this.TextBox3.Text + "','" + this.TextBox4.Text + "','" + this.TextBox5.Text + "')";
try
{
myconnection.Open();
SqlCommand mycommand = new SqlCommand(str_update, myconnection);
mycommand.ExecuteNonQuery();
myconnection.Close();
return "数据更新完成!";
}
catch (Exception ex)
{ myconnection.Close(); return ex.Message.ToString(); }
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询