I've written a simple form handler script using ASP3.0/VBScript and would like to add the inputted data (via the web) to an Access database located on my server. I'm using the OLEDB method to connect like so:
Cst = "PROVIDER=Microsoft.Jet.OLEDB.4.0;" & _
"DATA SOURCE=" & Server.MapPath("DataBase.mdb")
Dim Conn
Set Conn = CreateObject("ADODB.Connection")
Conn.Mode = 3
Conn.Open Cst
Blah Blah Blah...
I currently have a file named ADOVBS.inc included at the top but 开发者_高级运维would like to ditch it because I feel it's inefficient and wasteful. I'd like to define the constants as I need them- but I don't know how. What ADO constants would I need to define and where? The book that I'm using basically says "forget about that- pound include those 400 or so boogers in there and don't ask stupid questions!"
Any specific examples/help would be greatly appreciated.
Thanks,
you have a couple of options to choose from. You can reference the metadata library in your page ( or in your global.asa file ) with
<!--
METADATA
TYPE="TypeLib"
NAME="Microsoft ActiveX Data Objects 2.5 Library"
UUID="{00000205-0000-0010-8000-00AA006D2EA4}"
VERSION="2.5"
-->
or
you can simply copy a few constants from the adovbs file into your page to cover your needs. For example
Const adCmdText = 1 'Evaluate as a textual definition
Const adCmdStoredProc = 4 'Evaluate as a stored procedure
Of course that the answer is "Forget about that- pound include those 400 or so boogers in there and don't ask stupid questions!" :)
But since you insist:
The best way is to encapsulate all data access function in one .ASP
Let's call it dbHelper.asp
Then put all the DB functions in there, like:
''// run a query and returns a disconnected recordset
Function RunSQLReturnRS(sqlstmt, params())
On Error Resume next
''//Create the ADO objects
Dim rs , cmd
Set rs = server.createobject("ADODB.Recordset")
Set cmd = server.createobject("ADODB.Command")
''// Init the ADO objects & the stored proc parameters
cmd.ActiveConnection = GetConnectionString()
cmd.CommandText = sqlstmt
cmd.CommandType = adCmdText
collectParams cmd, params
''//Execute the query for readonly
rs.CursorLocation = adUseClient
rs.Open cmd, , adOpenForwardOnly, adLockReadOnly
If err.number > 0 then
BuildErrorMessage()
exit function
end if
''//Disconnect the recordset
Set cmd.ActiveConnection = Nothing
Set cmd = Nothing
Set rs.ActiveConnection = Nothing
''//Return the resultant recordset
Set RunSQLReturnRS = rs
End Function
At that point, you know that all you ado constants are in this file and you can start replacing them as wished.
Relevant list of constants can be found here: https://web.archive.org/web/20190225142339/http://www.4guysfromrolla.com:80/ASPScripts/PrintPage.asp?REF=/webtech/faq/beginner/faq7.shtml
I'll copy it here as well:
'---- CursorTypeEnum Values ----
Const adOpenForwardOnly = 0
Const adOpenKeyset = 1
Const adOpenDynamic = 2
Const adOpenStatic = 3
'---- CursorOptionEnum Values ----
Const adHoldRecords = &H00000100
Const adMovePrevious = &H00000200
Const adAddNew = &H01000400
Const adDelete = &H01000800
Const adUpdate = &H01008000
Const adBookmark = &H00002000
Const adApproxPosition = &H00004000
Const adUpdateBatch = &H00010000
Const adResync = &H00020000
Should be enough for inserting/selecting/updating records in database.
精彩评论