private void btnDel_Click(object sender, EventArgs e) { { string id = this.txtID.Text; SqlConnection conne = new SqlConnection("server=(local);database=FilmDB;integrated security=true"); string sql = string.Format("delete FilmInfo where F_ID='{0}'", id); SqlCommand comm = new SqlCommand(sql, conne); conne.Open(); int count = comm.ExecuteNonQuery(); conne.Close(); if (count > 0) { MessageBox.Show("电影删除成功"); DBHelp help1 = new DBHelp(); string sql1 = "SELECT * FROM FilmInfo"; DataTable table = help1.GetTableBySql(sql1); this.dataGridView1.DataSource = table; } else { MessageBox.Show("删除失败,请重试"); } } }
private void FrmFilmDel_Load(object sender, EventArgs e) { //创建一个工具箱实例 DBHelp help = new DBHelp(); string sql = "SELECT * FROM FilmInfo"; DataTable table = help.GetTableBySql(sql); this.dataGridView1.DataSource = table; }
private void FrmChaxun_Load(object sender, EventArgs e) { //创建一个工具箱实例 DBHelp help = new DBHelp(); string sql = "SELECT * FROM RoomInfo"; DataTable table = help.GetTableBySql(sql); this.Chaxun.DataSource = table; }
private void btnOK_Click(object sender, EventArgs e) { //第一步:创建连接对象 SqlConnection conn = new SqlConnection("server=(local);database=FilmDB;integrated security=true"); //取界面中的值 string name = this.txtName.Text; int type = this.rad3D.Checked ? 1 : 0; int sCount = Convert.ToInt32(this.txtCount.Text); //声明一个字符串取表示要执行的命令 string sql = string.Format("INSERT INTO RoomInfo VALUES('{0}',{1},{2})", name, type, sCount); //声明工具箱对象 DBHelp help = new DBHelp(); int count = help.ExecuteIDUBySql(sql); //根据执行结果,判断是否执行成功,给用户提示 if (count > 0) { MessageBox.Show("影厅信息添加成功!"); } else { MessageBox.Show("影厅信息添加失败,请检查!"); } }