日期:2014-05-18 浏览次数:21149 次
  
  private void button1_Click(object sender, EventArgs e)
        {
            string sqlConnection=null;
                if (textBox1.Text == "")
                { MessageBox.Show("请输入科室编号!"); return; }
                if (textBox2.Text == "")
                { MessageBox.Show("请输入科室名称!"); return; }
                sqlConnection = "insert into 科室表 values(" + textBox1.Text + "," + textBox2.Text + ")";
          if (ExeSQL(sqlConnection))
               MessageBox.Show("插入成功!");
           else MessageBox.Show("插入失败!");
           
        }
public bool ExeSQL(string strSQL)
        {
            bool resultState = false;
           
            oleDbConnection.Open();
            System.Data.OleDb.OleDbTransaction myTrans = oleDbConnection.BeginTransaction();
            OleDbCommand command = new OleDbCommand(strSQL, oleDbConnection, myTrans); 
            try
            {
                command.ExecuteNonQuery();
                myTrans.Commit();
                resultState = true;
            }
            catch
            {
                myTrans.Rollback();
                resultState = false;
            }
            finally
            {
                oleDbConnection.Close();
            }
            return resultState;
        }