瞳窟밗잿鑒앴욋 잚

2018-09-06 10:30

阅读:1198

  <%
ClassRLManDBCls
PrivatesDBPath,RLConn,sDBType,sServerName,sUserName,sPassword
PublicCount
PrivateSubClass_Initialize()
sDBType=
EndSub
PrivateSubClass_Terminate()
IfIsObject(RlConn)Then
RlConn.Close
SetRlConn=Nothing
Endif
EndSub
PublicPropertyLetDBType(ByValstrVar)
sDBType=strVar
EndProperty
PublicPropertyLetServerName(ByValstrVar)
sServerName=strVar
EndProperty
PublicPropertyLetUserName(ByValstrVar)
sUserName=strVar
EndProperty
PublicPropertyLetPassword(ByValstrVar)
sPassword=strVar
EndProperty
?阮초暄駙讐렙?
PublicPropertyLetDBPath(ByValstrVar)
sDBPath=strVar
SelectCasesDBType
CaseSQL
StrServer=sServerName鑒앴욋륩蛟포츰
StrUid=sUserName퀭돨되쩌琅뵀
StrSaPwd=sPassword퀭돨되쩌쵱쯤
StrDbName=sDBPath퀭돨鑒앴욋츰냔
sDBPath=driver={SQLserver};server=&StrServer&;uid=&StrUid&;pwd=&StrSaPwd&;database=&StrDbName
CaseACCESS,
sDBPath=Provider=Microsoft.Jet.OLEDB.4.0;DataSource=&Server.MapPath(sDBPath)
EndSelect
CheckDataRLConn,sDbPath
EndProperty

쇱꿴鑒앴욋졍쌈,(긴좆츰,젯쌈俚눔)
PrivateSubCheckData(DataConn,ConnStr)
OnErrorResumeNext
DataConn.OpenConnStr
IfErrThen
Err.Clear
SetDataConn=Nothing
ErrMsg(鑒앴욋젯쌈놔댄:&Replace(ConnStr,\,\\)&,\n헝쇱꿴젯쌈俚눔,횅훰퀭渴흙돨鑒앴욋斤口角뤠攣횅。)
Response.End
EndIf
EndSub
쇱꿴깊角뤠닸瞳
FunctionCheckTable(TableName)
OnErrorResumeNext
RLConn.Execute(select*From&TableName)
IfErr.Number<>0Then
Err.Clear()
CallErrMsg(댄轎瓊刻:&Err.Description)
CheckTable=False
Else
CheckTable=True
EndIf
EndFunction

댄轎瓊刻斤口(句口)
PrivateSubErrMsg(msg)
Response.Writemsg
Response.Flush
EndSub
---------------------------------------俚뙈令돨꾸鱗-----------------------------------------------
錦맣俚뙈돨令
PublicSubupColumn(ByValTableName,ByValColumnName,ByValValueText,ByValWhereStr)
OnErrorResumeNext
IfWhereStr<>Then
IfInStr(WhereStr,Where)<=0Then
WhereStr=Where&WhereStr
Endif
Else
WhereStr=
Endif
RLConn.Execute(update&TableName&set&ColumnName&=&ValueText&&WhereStr)
IfErr.Number<>0Then
CallErrMsg(댄轎瓊刻:&Err.Description)
Err.Clear()
EndIf

EndSub

獵契SQL刀얌
PublicSubExecute(StrSql)
SetRsCount=Server.CreateObject(ADODB.RecordSet)
OnErrorResumeNext
RsCount=RLConn.Execute(StrSql)
IfLeft(StrSql,12)=SelectCountThenCount=RsCount(0)
IfErr.Number<>0Then
CallErrMsg(댄轎瓊刻:&Err.Description)
Err.Clear()
EndIf
RsCount.Close
SetRsCount=Nothing
EndSub
---------------------------------------乞多(Index),柬暠(View),寮숩꾸鱗-----------------------------------------------
警속俚뙈乞多
PublicFunctionAddIndex(ByValTableName,ByValIndexName,ByValValueText)
OnErrorResumeNext
RLConn.Execute(CREATEINDEX&IndexName&ON[&TableName&]([&ValueText&]))
IfErr.Number<>0Then
CallErrMsg(瞳&TableName&깊劤쉔&IndexName&乞多댄轎,覩凜&Err.Description&헝癎묏錦맣맡乞多。)
Err.Clear()
AddIndex=False
Else
AddIndex=True
EndIf
EndFunction

?쓱逅芍桶?
PublicFunctionDelIndex(ByValTableName,ByValIndexName)
OnErrorResumeNext
RLConn.Execute(drop왕목INDEX[&TableName&].&IndexName)
IfErr.Number<>0Then
CallErrMsg(瞳&TableName&깊?쓱?&IndexName&乞多댄轎,覩凜&Err.Description&헝癎묏?쓱燻촉桶爻?)
Err.Clear()
DelIndex=False
Else
DelIndex=True
EndIf
EndFunction
뫘맣깊TableName돨땍屢겉俚뙈ColumnName?琬ぶ太?
PublicFunctionAddPRIMARYKEY(ByValTableName,ByValColumnName)
OnErrorResumeNext
TableName=Replace(Replace(TableName,[,),],)
RLConn.Execute(ALTERTABLE&TableName&ADDCONSTRAINTPK_&TableName&PRIMARYKEY(&ColumnName&))
IfErr.Number<>0Then
CallErrMsg(瞳&TableName&쉥俚뙈&ColumnName&警속槨寮숩珂놔댄,覩凜&Err.Description&헝癎묏錦맣맡俚뙈橄昑。)
Err.Clear()
AddPRIMARYKEY=False
Else
AddPRIMARYKEY=True
EndIf
EndFunction
뫘맣깊TableName돨땍屢겉俚뙈ColumnName寮숩돨땍屢?쓱?
PublicFunctionDelPRIMARYKEY(ByValTableName,ByValColumnName)
OnErrorResumeNext
RLConn.Execute(ALTERTABLE&TableName&drop왕목PRIMARYKEY(&ColumnName&))
IfErr.Number<>0Then
CallErrMsg(瞳&TableName&쉥俚뙈&ColumnName&寮숩돨땍屢?쓱輝교測粒г凜&Err.Description&헝癎묏錦맣맡俚뙈橄昑。)
Err.Clear()
DelPRIMARYKEY=False
Else
DelPRIMARYKEY=True
EndIf
EndFunction
쇱꿴寮숩角뤠닸瞳,럿쀼맡깊돨寮숩츰
FunctionGetPrimaryKey(TableName)
onerrorResumeNext
DimRsPrimary
GetPrimaryKey=
SetRsPrimary=RLConn.OpenSchema(28,Array(Empty,Empty,TableName))
IfNotRsPrimary.EofThenGetPrimaryKey=RsPrimary(COLUMN_NAME)
SetRsPrimary=Nothing
IfErr.Number<>0Then
CallErrMsg(鑒앴욋꼇連넣쇱꿎鑒앴깊&TableName&돨寮숩。覩凜:&Err.Description)
Err.Clear()
EndIf
EndFunction
---------------------------------------깊써뭐꾸鱗-----------------------------------------------
警속劤俚뙈
PublicFunctionAddColumn(TableName,ColumnName,ColumnType)
OnErrorResumeNext
RLConn.Execute(AlterTable[&TableName&]Add[&ColumnName&]&ColumnType&)
IfErrThen
ErrMsg(劤쉔&TableName&깊櫓俚뙈댄轎,헝癎땡쉥鑒앴욋櫓<B>&ColumnName&</B>俚뙈쉔접,橄昑槨<B>&ColumnType&</B>,覩凜&Err.Description)
Err.Clear
AddColumn=False
Else
AddColumn=True
EndIf
EndFunction
뫘맣俚뙈繫痰변鑒
PublicFunctionModColumn(TableName,ColumnName,ColumnType)
OnErrorResumeNext
RLConn.Execute(AlterTable[&TableName&]AlterColumn[&ColumnName&]&ColumnType&)
IfErrThen
CallErrMsg(뫘맣&TableName&깊櫓俚뙈橄昑댄轎,헝癎땡쉥鑒앴욋櫓<B>&ColumnName&</B>俚뙈뫘맣槨<B>&ColumnType&</B>橄昑,覩凜&Err.Description)
Err.Clear
ModColumn=False
Else
ModColumn=True
EndIf
EndFunction
?쓱洶伶胱ⓖ첬鑒
PublicFunctionDelColumn(TableName,ColumnName)
OnErrorResumeNext
IfsDBType=SQLTHen
RLConn.Execute(AlterTable[&TableName&]drop왕목Column[&ColumnName&])
Else
RLConn.Execute(AlterTable[&TableName&]drop왕목[&ColumnName&])
Endif
IfErrThen
CallErrMsg(?쓱?nbsp;&TableName&깊櫓俚뙈댄轎,헝癎땡쉥鑒앴욋櫓<B>&ColumnName&</B>俚뙈?쓱酵г凜&Err.Description)
Err.Clear
DelColumn=False
Else
DelColumn=True
EndIf
EndFunction
---------------------------------------깊꾸鱗---------------------------------------------------
댔역깊츰뚤蹶
PrivateSubReNameTableConn()
OnErrorResumeNext
SetobjADOXDatabase=Server.CreateObject(ADOX.Catalog)
objADOXDatabase.ActiveConnection=ConnStr
IfErrThen
ErrMsg(쉔접뫘맣깊츰뚤蹶놔댄,퀭杰狼?薨떫커欖我뿟㎡獵羌冬徵?杏餠?콘矜狼癎땡뫘맣깊츰,覩凜&Err.Description)
Response.End
Err.Clear
EndIf
EndSub
밑균깊츰뚤蹶
PrivateSubCloseReNameTableConn()
SetobjADOXDatabase=Nothing
Conn.Close
SetConn=Nothing
EndSub
뫘맣鑒앴욋깊츰,흙왯꽝鑒:일깊츰、劤깊츰
PublicFunctionRenameTable(oldName,newName)
OnErrorResumeNext
CallReNameTableConn
IfErrThen
CallErrMsg(뫘맣깊츰댄轎,헝癎땡쉥鑒앴욋櫓<B>&oldName&</B>깊츰뫘맣槨<B>&newName&</B>,覩凜&Err.Description)
Err.Clear
RenameTable=False
Else
RenameTable=True
EndIf
CallCloseReNameTableConn
EndFunction
?쓱逅雀ⓖ첬鑒
PublicFunctionDelTable(TableName)
OnErrorResumeNext
RLConn.Execute(drop왕목Table[&TableName&])
IfErrThen
ErrMsg(?쓱?nbsp;&TableName&깊댄轎,헝癎땡쉥鑒앴욋櫓<B>&TableName&</B>깊?쓱酵г凜&Err.Description)
Err.Clear
DelTable=False
Else
DelTable=True
EndIf
EndFunction

쉔접劤깊
PublicFunctionCreateTable(ByValTableName,ByValFieldList)
DimStrSql
IfsDBType=SQLTHen
StrSql=CREATETABLE[&TableName&](&FieldList&)
Else
StrSql=CREATETABLE[&TableName&]
Endif
RLConn.Execute(StrSql)
IfErr.Number<>0Then
CallErrMsg(劤쉔&TableName&깊댄轎,覩凜&Err.Description&)
Err.Clear()
CreateTable=False
Else
CreateTable=True
EndIf
EndFunction


---------------------------------------鑒앴욋꾸鱗-----------------------------------------------

쉔접鑒앴욋匡숭
PublicfunctionCreateDBfile(byValdbFileName,byValSavePath)
OnerrorresumeNext
SavePath=Replace(SavePath,/,\)
IfRight(SavePath,1)<>\OrRight(SavePath,1)<>/ThenSavePath=Trim(SavePath)&\
IfLeft(dbFileName,1)=\OrLeft(dbFileName,1)=/ThendbFileName=Trim(Mid(dbFileName,2,Len(dbFileName)))
IfDbExists(AppPath()&SavePath&dbFileName)Then
ErrMsg(뚤꼇폅,맡鑒앴욋綠쒔닸瞳!&AppPath()&SavePath&dbFileName)
CreateDBfile=False
Else
Response.WriteAppPath()&SavePath&dbFileName
DimCa
SetCa=Server.CreateObject(ADOX.Catalog)
IfErr.number<>0Then
ErrMsg(轟랬쉔접,헝쇱꿴댄轎斤口<br>&Err.number&<br>&Err.Description)
Err.Clear
CreateDBfile=False
Exitfunction
EndIf
callCa.Create(Provider=Microsoft.Jet.OLEDB.4.0;DataSource=&AppPath()&SavePath&dbFileName)
SetCa=Nothing
CreateDBfile=True
EndIf
Endfunction

꿴冷鑒앴욋匡숭角뤠닸瞳
PrivatefunctionDbExists(byValdbPath)
OnErrorresumeNext
Dimc
Setc=Server.CreateObject(ADODB.Connection)
c.OpenProvider=Microsoft.Jet.OLEDB.4.0;DataSource=&dbPath
IfErr.number<>0Then
Err.Clear
DbExists=false
else
DbExists=True
EndIf
setc=nothing
Endfunction
혤뎠품廬茄쨌쓺
PrivatefunctionAppPath()
AppPath=Server.MapPath(./)
IfRight(AppPath,1)=\THen
AppPath=AppPath
ELse
AppPath=AppPath&\
Endif
Endfunction

?쓱譎뻗輜暄駙須캬
PublicfunctionDeleteDBFile(filespec)
filespec=AppPath()&filespec
Dimfso
Setfso=CreateObject(Scripting.FileSystemObject)
IfErr.number<>0Then
ErrMsg(?쓱烋캬랙?駭鵲?헝꿴였댄轎斤口:&Err.number&&Err.Description&<br>)
Err.Clear
DeleteDBFile=False
EndIf
IfDbExists(filespec)THen
callfso.DeleteFile(filespec)
DeleteDBFile=True
Else
ErrMsg(?쓱烋캬랙?駭鵲?헝꿴였댄轎斤口:&Err.number&&Err.Description&<br>)
DeleteDBFile=False
ExitFunction
Endif
Setfso=Nothing
Endfunction

錦맣寧몸鑒앴욋츰
PublicfunctionRenameDBFile(filespec1,filespec2)
filespec1=AppPath()&filespec1:filespec2=AppPath()&filespec2
Dimfso
Setfso=CreateObject(Scripting.FileSystemObject)
IfErr.number<>0Then
ErrMsg(錦맣匡숭츰珂랙?駭鵲?헝꿴였댄轎斤口:&Err.number&&Err.Description)
Err.Clear
RenameDBFile=False
EndIf
IfDbExists(filespec1)THen
callfso.CopyFile(filespec1,filespec2,True)
callfso.DeleteFile(filespec1)
RenameDBFile=True
Else
ErrMsg(都匡숭꼇닸瞳!!!)
RenameDBFile=False
ExitFunction
Endif
Setfso=Nothing
Endfunction
箕鍵鑒앴욋
PublicFunctionCompactDBFile(strDBFileName)
DimJet_Conn_Partial
DimSourceConn
DimDestConn
DimoJetEngine
DimoFSO

Jet_Conn_Partial=Provider=Microsoft.Jet.OLEDB.4.0;Datasource=

SourceConn=Jet_Conn_Partial&AppPath()&strDBFileName
DestConn=Jet_Conn_Partial&AppPath()&Temp&strDBFileName
SetoFSO=Server.CreateObject(Scripting.FileSystemObject)
SetoJetEngine=Server.CreateObject(JRO.JetEngine)

WithoFSO
IfNot.FileExists(AppPath()&strDBFileName)Then
ErrMsg(鑒앴욋匡숭灌冷돕!!!!)
Stop
CompactDBFile=False
ExitFunction
Else
If.FileExists(AppPath()&Temp&strDBFileName)Then
ErrMsg(꼇列돛돨댄轎!!!)
.DeleteFile(AppPath()&Temp&strDBFileName)
CompactDBFile=False
ExitFunction
EndIf
EndIf
EndWith

WithoJetEngine
EndWith

oFSO.DeleteFileAppPath()&strDBFileName
oFSO.MoveFileAppPath()&Temp&strDBFileName,AppPath()&strDBFileName

SetoFSO=Nothing
SetoJetEngine=Nothing
CompactDBFile=True
EndFunction
EndClass
DimManDb
SetManDb=NewRLManDBCls
//---------젯쌈SQL鑒앴욋--------------
ManDb.DBType=SQL
ManDb.ServerName=TAO-KUIZU
ManDb.Password=123456
ManDb.DBPath=hhstuss
ManDb.CreateTablecexo255,idintNotNullPRIMARYKEY,Namevarchar(20)NotNull쉔접깊(깊츰)
ManDb.ReNameTablecexo255,cexo2552깊맣츰(앉깊츰,劤깊츰)(痰莉숭)
ManDb.DelTablecexo255?쓱逅粒㉠勺滎?
ManDb.AddColumncexo255,Sex,varchar(2)null쉔접깊써뭐(깊츰,俚뙈츰,鑒앴잚謹)
ManDb.ModColumncexo255,name,intNotnull錦맣깊써뭐(깊츰,俚뙈츰,劤鑒앴잚謹)_
ManDb.DelColumncexo255,Sex?쓱逅蔗昭묍㉠勺滎ё伶光滎?
ManDb.AddIndexcexo255,i_ID,ID쉔접깊乞多(깊츰,乞多츰,乞多俚뙈츰)
ManDb.DelIndexcexo255,i_ID?쓱逅芍桶酵㉠勺滎?桶毁滎?
ManDb.AddPRIMARYKEYcexo255,name쉔접깊寮숩(깊츰,寮숩俚뙈츰)
ManDb.DelPRIMARYKEYcexo255,name?쓱逅潛太花㉠勺滎е太簧伶光滎?
Response.WriteManDb.GetPrimaryKey(cexo255)혤깊돨寮숩(깊츰)
ManDb.upColumncexo255,id,12345,name=1錦맣俚뙈돨令
ManDb.Executeinsert왕목intocexo255(id,Name)values(2,2)警속션쩌
ManDb.ExecuteUpdatecexo255Setid=3WhereName=2錦맣션쩌
ManDb.Executedelete왕목Fromcexo255WhereName=2?쓱薨픈?
ManDb.Execute(SelectCount(*)Fromcexo255):Response.WriteManDb.Count固셕션쩌몸鑒
IfManDb.CheckTable(StudInfo)THenResponse.WriteStudInfo깊닸瞳!!!ElseResponse.WriteStudInfo깊꼇닸瞳!!!
//-----------End--------------------------
//---------젯쌈Access鑒앴욋--------------
ManDb.DBType=ACCESS
ManDb.DBPath=test.mdb
ManDb.CreateDBfiletest2.mdb,쉔접鑒앴욋(鑒앴욋츰,괏닸쨌쓺)
ManDb.DeleteDBFile(test2.mdb)?쓱輝暄駙授㉹暄駙輸滎?
ManDb.RenameDBFiletest2.mdb,test3.mdb鑒앴욋맣츰(앉鑒앴욋츰,劤鑒앴욋츰)
ManDb.CompactDBFile(test3.mdb)箕鍵鑒앴욋(鑒앴욋츰)
ManDb.CreateTabledw,쉔접깊(깊츰)
ManDb.ReNameTabledw,dw2깊맣츰(앉깊츰,劤깊츰)(痰莉숭)_
ManDb.DelTabledw?쓱逅粒㉠勺滎?
ManDb.AddColumncexo255,name,varchar(255)Notnull쉔접깊써뭐(깊츰,俚뙈츰,鑒앴잚謹)
ManDb.ModColumncexo255,name,intNotnull錦맣깊써뭐(깊츰,俚뙈츰,劤鑒앴잚謹)
ManDb.DelColumncexo255,name?쓱逅蔗昭묍㉠勺滎ё伶光滎?
ManDb.AddIndexcexo255,UserID,ID쉔접깊乞多(깊츰,乞多츰,乞多俚뙈츰)
ManDb.DelIndexcexo255,UserID?쓱逅芍桶酵㉠勺滎?桶毁滎?
ManDb.AddPRIMARYKEYcexo255,id쉔접깊寮숩(깊츰,寮숩俚뙈츰)
ManDb.DelPRIMARYKEYcexo255,id?쓱逅潛太花㉠勺滎е太簧伶光滎?
Response.WriteManDb.GetPrimaryKey(cexo255)혤깊돨寮숩(깊츰)
ManDb.upColumncexo255,id,12345,id=12錦맣俚뙈돨令
ManDb.Executeinsert왕목intocexo255(id)values(789)警속션쩌
ManDb.ExecuteUpdatecexo255Setid=wxfWhereid=789錦맣션쩌
ManDb.Executedelete왕목Fromcexo255Whereid=wxf?쓱薨픈?
ManDb.Execute(SelectCount(*)Fromcexo255):Response.WriteManDb.Count固셕션쩌몸鑒
IfManDb.CheckTable(StudInfo)THenResponse.WriteStudInfo깊닸瞳!!!ElseResponse.WriteStudInfo깊꼇닸瞳!!!
//-----------End--------------------------
SetManDb=Nothing
%>


评论


亲,登录后才可以留言!