protected void Button1_Click(object sender, EventArgs e)
{
{
try
{
string connstr = "Data Source=Localhost;Initial Catalog=twxy1;Integrated Security=True";
SqlConnection conn = new SqlConnection(connstr);
conn.Open();
SqlCommand cmd = new SqlCommand("INSERT INTO [tj_data]([统计日期]) VALUES ('" + this.TextBox1.Text.Trim() + "')", conn);
cmd.ExecuteNonQuery();//注意这句
conn.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString(), "系统提示:");
}
}
}
c#中按钮提交事件的插入数据到数据库的代码
最新推荐文章于 2018-11-26 22:48:58 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)