Parameterized query for Access, with VBScript (ASP) and C # (asp.net) functions 1th/2 page _access

Source: Internet
Author: User
Recent project needs to use access to do database development Web projects
Look at the forum and many people asked about access being injected security issues
A lot of people are still replacing special characters with replace, but it doesn't make much of a deal
Today I'm going to share with you some of the methods and experiences of using access parameterized queries
Hope for everyone to have some inspiration, there is a wrong place to hope that the experts to teach a lot

asp.net use OleDbCommand new OleDbParameter to create parameter goods query
ASP uses Command's CreateParameter method to create parameterized query
(SQL stored procedure queries are also established by this method)

asp.net C # syntax
----------------------------------------------------------------------------

Copy Code code as follows:

OleDbParameter parm = new OleDbParameter (Name, Type, Direction, Size, Value);
(In fact, it has seven overloads, and you can see it in vs.net.)
Parameters
Name Optional, string that represents the Parameter object name.
Type optional, long integer value specifying the Parameter object data type.
Direction optional, long integer value specifying the Parameter object type ...
Size optional, Long value specifying the maximum length of the parameter value in characters or bytes.
Value optional, Variant type, specifying the values of the Parameter object.
Here's an example of all the News Tsing published
-------------------------------------------------------
Sql= "SELECT * from Newss where username=?" ORDER BY ID "
Note that the condition of the query is indicated by a number.
OleDbConnection conn = new OleDbConnection (connstring);
OleDbCommand cmd = new OleDbCommand (sql,conn);
OleDbParameter parm = new OleDbParameter ("temp", OleDbType.VarChar, 50);
Temp is a parameter object that can be arbitrarily defined, OleDbType.VarChar specified as a string, length 50
Parm. Direction = ParameterDirection.Input;
Specify its type input parameters
Cmd. Parameters.Add (Parm);
Cmd. parameters["Temp"]. Value = "Tsing";
Query tsing, can also be written as CMD. Parameters[0]
Conn. Open ();
Cmd. ExecuteReader ();

----------------------------------------------------------------------------
ASP VBScript Syntax
----------------------------------------------------------------------------

Copy Code code as follows:

Set parameter = command. CreateParameter (Name, Type, Direction, Size, Value)
Parameter ditto
Here's an example of all the News Tsing published
------------------------------------------------------
ET conn = Server.CreateObject ("Adodb.connection")
Conn. ConnectionString = connstring
Conn.Open ()
Set mycmd = Server.CreateObject ("Adodb.command")
myCMD. Activeconnection=conn
Mycmd.commandtext=sql
myCMD. Prepared = True
Set Mypar = myCMD. CreateParameter ("temp", 129,1,50, "Tsing")
myCMD. Parameters.Append Mypar
Set myrs = myCMD. Execute

---------------------------------------------------------------------------
The same as the above basically different local method is ASP in the expression of the parameters of the different
129 for adchar,1 is to indicate the input parameter (is actually the default value)
Please refer to Microsoft's Adovb.inc:

Copy Code code as follows:

'----ParameterDirectionEnum Values----
Const Adparamunknown = 0
Const adParamInput = 1
Const adParamOutput = 2
Const adParamInputOutput = 3
Const adParamReturnValue = 4
'----DataTypeEnum Values----
Const adempty = 0
Const Adtinyint = 16
Const adSmallInt = 2
Const Adinteger = 3
Const adBigInt = 20
Const Adunsignedtinyint = 17
Const Adunsignedsmallint = 18
Const Adunsignedint = 19
Const Adunsignedbigint = 21
Const Adsingle = 4
Const addouble = 5
Const adcurrency = 6
Const Addecimal = 14
Const adnumeric = 131
Const Adboolean = 11
Const Aderror = 10
Const aduserdefined = 132
Const advariant = 12
Const adIDispatch = 9
Const adIUnknown = 13
Const Adguid = 72
Const addate = 7
Const adDBDate = 133
Const adDBTime = 134
Const adDBTimeStamp = 135
Const ADBSTR = 8
Const Adchar = 129
Const adVarChar = 200
Const adLongVarChar = 201
Const Adwchar = 130
Const adVarWChar = 202
Const adLongVarWChar = 203
Const adbinary = 128
Const advarbinary = 204
Const Adlongvarbinary = 205

Current 1/2 page 12 Next read the full text
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.