protected void Button1_Click1(object sender, EventArgs e)
{
//实例化对象
SqlConnection myConn = GetConnection();
myConn.Open(); //打开数据库
string addTxt = this.TextClass.Text.Trim(); //获取输入
// 添加到 tb_Class 表中 CLassName字段中 值为 addTxt
string sqlStr = "insert into db_09.dbo.tb_Class(ClassName) values('" + addTxt + "')";
//SQL命令,使用(SQL添加字符串, SQL链接字符串)
SqlCommand myCmd = new SqlCommand(sqlStr, myConn);
myCmd.ExecuteNonQuery(); //执行命令
myCmd.Clone(); //关闭链接
this.bind(); //使用bind方法更新 显示数据集合
}
C# SQL添加记录
最新推荐文章于 2024-04-28 17:27:20 发布