PublicFunctionConnectString()_AsStringConnectString="FileDSN=info.dsn;UID=sa;PWD=23""連線字元器,改成你自己的EndFunctionPublicFunctionExecuteSQL(ByValSQL_AsString,MsgStringAsString)_AsADODB.Recordset"這裡是執行SQL語句,你只需要呼叫這個方法,把SQL查詢語句引數傳進來,最後返回一個RecordsetDimcnnAsADODB.ConnectionDimrstAsADODB.RecordsetDimsTokens()AsStringOnErrorGoToExecuteSQL_ErrorsTokens=Split(SQL)Setcnn=NewADODB.Connectioncnn.OpenConnectStringIfInStr("INSERT,DELETE,UPDATE",_UCase$(sTokens(0)))Thencnn.ExecuteSQLMsgString=sTokens(0)&_"querysuccessful"ElseSetrst=NewADODB.Recordsetrst.OpenTrim$(SQL),cnn,_adOpenKeyset,_adLockOptimistic"rst.MoveLast"getRecordCountSetExecuteSQL=rstMsgString="查詢到"&rst.RecordCount&_"條記錄"EndIfExecuteSQL_Exit:Setrst=NothingSetcnn=NothingExitFunctionExecuteSQL_Error:MsgString="查詢錯誤:"&_Err.DescriptionResumeExecuteSQL_ExitEndFunctionPublicFunctionTesttxt(txtAsString)AsBooleanIfTrim(txt)=""ThenTesttxt=FalseElseTesttxt=TrueEndIfEndFunction
PublicFunctionConnectString()_AsStringConnectString="FileDSN=info.dsn;UID=sa;PWD=23""連線字元器,改成你自己的EndFunctionPublicFunctionExecuteSQL(ByValSQL_AsString,MsgStringAsString)_AsADODB.Recordset"這裡是執行SQL語句,你只需要呼叫這個方法,把SQL查詢語句引數傳進來,最後返回一個RecordsetDimcnnAsADODB.ConnectionDimrstAsADODB.RecordsetDimsTokens()AsStringOnErrorGoToExecuteSQL_ErrorsTokens=Split(SQL)Setcnn=NewADODB.Connectioncnn.OpenConnectStringIfInStr("INSERT,DELETE,UPDATE",_UCase$(sTokens(0)))Thencnn.ExecuteSQLMsgString=sTokens(0)&_"querysuccessful"ElseSetrst=NewADODB.Recordsetrst.OpenTrim$(SQL),cnn,_adOpenKeyset,_adLockOptimistic"rst.MoveLast"getRecordCountSetExecuteSQL=rstMsgString="查詢到"&rst.RecordCount&_"條記錄"EndIfExecuteSQL_Exit:Setrst=NothingSetcnn=NothingExitFunctionExecuteSQL_Error:MsgString="查詢錯誤:"&_Err.DescriptionResumeExecuteSQL_ExitEndFunctionPublicFunctionTesttxt(txtAsString)AsBooleanIfTrim(txt)=""ThenTesttxt=FalseElseTesttxt=TrueEndIfEndFunction