资源描述:
《vb操作数据库的基本函数模块》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、BackTransparentImage_ModuleOptionExplicitPublicConnAsNewADODB.ConnectionPublicRsAsNewADODB.Recordset'临时表'三个系统表PublicUserTableAsNewADODB.Recordset'用户表PublicOpeRecordAsNewADODB.Recordset'操作记录表PublicTablesInfoAsNewADODB.Recordset'操作表信息PublicTypeTabaleRecordsetsTNu
2、mberAsLongTNameAsStringTRecordsetAsADODB.RecordsetEndTypePublicTRS()AsTabaleRecordsetsPublicFunctionOpenDataBase(ByValPathAsString,ByValPassWordAsString)AsLongDimiAsLongOnErrorGoToerrHandle'打开数据库IfTrim(PassWord)=""ThenConn.ConnectionString="Provider=Microsoft.J
3、et.OLEDB.4.0;DataSource="&Path&";PersistSecurityInfo=False;"ElseConn.ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0;DataSource="&Path&";JetOLEDB:DatabasePassword="&PassWord&";PersistSecurityInfo=False;"EndIfConn.Open'活动三个系统表UserTable.Open"select*fromUsersTa
4、ble",Conn,adOpenDynamic,adLockPessimisticOpeRecord.Open"select*fromOpeRecords",Conn,adOpenDynamic,adLockPessimisticTablesInfo.Open"select*fromTablesInfo",Conn,adOpenDynamic,adLockPessimistic'得到数据表数组ReDimTRS(0):i=0IfTablesInfo.EOF<>TrueAndTablesInfo.BOF<>TrueThe
5、nTablesInfo.MoveFirstDoWhileNotTablesInfo.EOFTRS(i).TName=TablesInfo.Fields("Name").ValueTRS(i).TNumber=iTRS(i).TRecordset.Open"select*from"&TRS(i).TName,Conn,adOpenDynamic,adLockPessimisticTablesInfo.MoveNextIfNotTablesInfo.EOFTheni=i+1ReDimPreserveTRS(i)ElseE
6、xitDoEndIfLoop'反馈操作结果IfConn.State=adStateOpenThenOpenDataBase=1MsgBox"成功打开数据库",vbOKOnly+vbInformation,"Information"ElseGoToerrHandleEndIfExitFunctionerrHandle:MsgBox"打开数据库时发生错误:"&Chr(13)&Err.Number&""&Err.Description,vbOKOnly+vbCritical,"发生错误"EndFunction'加载图片到数
7、据库PublicFunctionLoadPicToDatabase(ByValPicFileNameAsString)AsLongDimMStreamAsNewADODB.StreamMStream.Type=adTypeBinaryMStream.OpenMStream.LoadFromFileFileNameRs.Fields("Image").Value=MStream.ReadRs.UpdateMStream.CloseEndFunction'从数据库中输出图片PublicFunctionOutPicFrom
8、Database()AsPictureDimstmpicAsNewADODB.StreamDimStrPicTempAsStringIfNotIsNull(Rs.Fields("Image"))ThenStrPicTemp=App.Path&"temp.tmp"'临时文件,用来保存读出的图片Withstmpic.Type=adTypeBina