//打开数据源publicOleDbConnectionDBOpen(){stringstrConnection=Provider=Microsoft.Jet.OleDb.4.0;DataSource=;strConnection+=@Application.StartupPath+\\SMS.mdb;OleDbConnectionConn=newOleDbConnection(strConnection);Conn.Open();returnConn;}//关闭数据源连接publicvoidDBClose(OleDbConnectionConn){Conn.Close();Conn.Dispose();}//读数据库中的表publicOleDbDataReaderDBRead(OleDbConnectionConn,stringstr_select){OleDbCommandComm=newOleDbCommand(str_select,Conn);try{OleDbDataReaderReader=Comm.ExecuteReader();returnReader;}catch(Exceptionee){MessageBox.Show(ee.ToString());returnnull;}}//插入表publicBooleanInsertTable(OleDbConnectionConn,StringinsertStr){try{OleDbCommandComm=newOleDbCommand(insertStr,Conn);Comm.ExecuteNonQuery();MessageBox.Show(添加成功,成功,MessageBoxButtons.OK,MessageBoxIcon.Information);}catch(Exceptionee){MessageBox.Show(ee.ToString());returnfalse;}finally{Conn.Close();}returntrue;}//插入到Access表publicBooleanInsertAccessTable(OleDbConnectionConn,StringinsertStr){try{OleDbCommandComm=newOleDbCommand(insertStr,Conn);Comm.ExecuteNonQuery();}catch(Exceptionee){Conn.Close();returnfalse;}finally{Conn.Close();}returntrue;}//删除表publicBooleanDeleteRecords(OleDbConnectionConn,StringdeletStr){try{OleDbCommandComm=newOleDbCommand(deletStr,Conn);Comm.ExecuteNonQuery();MessageBox.Show(删除成功!,删除,MessageBoxButtons.OK,MessageBoxIcon.Information);}catch(Exceptione){returnfalse;}finally{Conn.Close();}returntrue;}//更新记录publicBooleanUpdateRecords(OleDbConnectionConn,StringupdataStr){try{OleDbCommandComm=newOleDbCommand(updataStr,Conn);Comm.ExecuteNonQuery();MessageBox.Show(修改成功!,修改,MessageBoxButtons.OK,MessageBoxIcon.Information);}catch(Exceptioneee){returnfalse;}finally{Conn.Close();}returntrue;}