[转] A function library for an ASP operation database made yesterday

xiaoxiao2021-03-06  65

'http://blog.9cbs.net/intereye/archive/2004/11/16/USEDB.ASPX<

'* ====================================================================================================================================== : database operations libraries' * author: intereye '*-mail: inteye@163.com' * Home page: http: //www.inteye.net '* BLOG: http: //blog.9cbs.net/intereye' * = =====================================

'* Function: OpenDB (DBTYPE, DBUSER, DBPASS, DBNAME, DBSERVER, DBPATH)' * Function: Open Database Connection '* Parameters: DBTYPE-> Database Type MDB Access Database || SQLServer SQLServer Database' * Parameters: DBUSER-> Access Database User Name '* Parameters: DBPASS-> Access Database Password' * Parameters: DBName-> Database Name '* Parameters: DBServer-> Database Host' * Parameters: dbpath-> Database Path Function OpenDB (DBTYPE, DBUSER, DBPASS, DBNAME , DBServer, dbpath) DIM conn set conn = server.createObject ("adoDb.connection" Select Case DBTYPE CASE "MDB": connStr = "driver = {Microsoft Access Driver (* .mdb)}; dbq =" & Server. MapPath ( "" & dbPath & dbName & "") case "SQLSERVER": connStr = "Provider = SQLOLEDB.1; Password =" & dbPass & "; Persist Security Info = True; User ID =" & dbUser & "; Initial Catalog =" & dbName & "; Data Source = "& dbserver &" "End Select Conn.open Connstr End Function" * Function: Add (TabName, FieldList, DBList) '* Function: Insert a record in the database' * Parameters: tabname-> Data table name '* Parameters: dblist -> Data table field name "* Parameters: fieldList-> Form variable name" * Return: 0 false || 1 True Function Add (TabName, DBList, FieldList) SQL = "Insert Into" & TabName & "(" Value = " "FIELD =" "for Each V in dblist Field = Field & V & "," Next Field = Left (Field, Len (Field) -1) Value = Field & ") Values ​​(" for Each V in Fieldlist if Request.form (V) <> "" Then Value = Value & " '"& Request.form (V) &", "Else Value = Value &"' "&"

v & "'," end if next value = left (value, lelue) -1) SQL = SQL & Value & ")" Conn.execute (SQL) Closedb () if Err Then Add = 0 else add = 1 End if End Function '* Function: Update (TabName, DBLIST, FIELDLIST, ID)' * Function: Update a record in the database '* Parameters: tabname-> DBLIST' * Parameters: dblist-> Database field name array '* Parameters: FIELDLIST-> Form Variable Number of Group' * Parameters: ID-> Data ID Number '* Back: 0 False || 1 True Function Update (TabName, DBLIST, FIELDLIST, ID) SQL = "Update" & Tabname & "SET" value = "" for i = 0 to Ubound (dblist) value = value & dblist (i) & "= '" = ") <>" "" "" "" ". Form (FieldList (i)) & "," Else Value = Value & FieldList (i) & "," End if Next value = left (value, len (value) -1) SQL = SQL & Value & "Where ID = "& id conn.execute (SQL) Closedb () if Err the update = 0 else update = 1 end if End function '* Function: Del (TabName, ID)' * Function: Delete a specified record in the database ' * Parameters: tabname-> Data table name '* Parameters: ID-> Data ID number * Back: 0 false || 1 True Function Del (TabName, ID) SQL = "Delete from" & Tabname & "WHER E ID in ("& ID &") "conn.execute (sql) closedb () if err then del = 0 else del = 1 end if end function '* Function: getRow (TabName, Fieldlist, Casestr)' * function: Get a line from the database '* parameter: tabname-> Data table name "* parameter: FieldList-> data field array" * parameters: CaseStr->

SQL condition statement Function GetRow (TabName, Fieldlist, Casestr) if not isarray (FieldList) Then FieldList = "*" else field = "" for Each Val in FIELDLILD = Field & Val & "," Next FieldList = Left (Field, LEN (FIELD) -1) End if SQL = "SELECT" & FieldList & "From" & TabName & CaseStr Set RS = Conn.execute (SQL) IF = 0 else getrow = 1 End If End Function '* Function: Closedb ()' * Function: Turn off the database connection and release the object function closedb () conn.close set conn = Nothing end function%>

转载请注明原文地址:https://www.9cbs.com/read-90445.html

New Post(0)