Some of the less-used operations of Access databases, ASP, create database files, create tables, create fields, Adox_ application tips

Source: Internet
Author: User
Tags numeric numeric value trim create database
Copy Code code as follows:

<% @LANGUAGE = "VBSCRIPT" codepage= "936"%>
<%
If Trim (Request.Form ("tablename"))

'----setting to open a database connection
dbs= "Data source=" +server.mappath ("Database.mdb") + "; provider=microsoft.jet.oledb.4.0; "
Set Conn=server.createobject ("Adodb.connection")
Conn.Open DBS


' Define ADOX, specify connection
Set ADOX =server.createobject ("ADOX.") Catalog ")
Set ADOX. ActiveConnection = conn

' Create TABLE, write properties
Set objtable= Server.CreateObject ("ADOX.") Table ")
' Objtable.name= ' Table3 '
Objtable.name=trim (Request.Form ("tablename")) ' form acquisition
' Objtable.parentcatalog = ADOX

' Define the first field
Set objcolumn = Server.CreateObject ("ADOX. Column ")
' Set Objcolumn.parentcatalog = ADOX
Objcolumn.name= "Column1"
objcolumn.type=202 ' data type 202 represents text,
objcolumn.attributes=2 ' 1--required fields, 2--non-required
ObjTable.Columns.Append Objcolumn
Set objcolumn = Nothing ' Clears the first field information


' Define a second field
Set objcolumn = Server.CreateObject ("ADOX. Column ")
' Set Objcolumn.parentcatalog = ADOX
Objcolumn.name= "Column2"
Objcolumn.type=3
objcolumn.attributes=2
ObjTable.Columns.Append Objcolumn
Set objcolumn = Nothing

ADOX. Tables.append objtable

Set ADOX = Nothing


%>

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 "/>
<title> Create tables and fields </title>
<style type= "Text/css" >
<!--
body,td,th {
font-size:12px;
}
-->
</style>
<body>
<p> ' Use the properties and collections of <strong> column</strong> objects, you can: <br/>
' Use the Name property to identify the column. <br/>
' Use the Type property to specify the data type of the column. <br/>
' Use the Attributes property to determine whether the column is a fixed length, or whether it can contain Null values. <br/>
' Use the DefinedSize property to specify the maximum size of the column. <br/>
' For numeric data values, use the NumericScale property to specify a range. <br/>
' For numeric data values, use the Precision property to specify the maximum precision. <br/>
' Use the ParentCatalog property to specify the parent Catalog of the column. <br/>
' For the key column, use the RelatedColumn property to specify the name of the related column in the related table. <br/>
' For indexed columns, use the SortOrder property to specify whether the sort order is ascending or descending. </p>
<p> data types are as follows table:</p>
<table border=1 cellpadding=4 cellspacing=4 cols=4 frame=box rules=all width=100%>

&LT;TR valign= "Top" >
<th Width=32%> Constants </TH>
<th width=13%> Value </TH>
<th width=55%> Description </TH>
</TR>

&LT;TR valign= "Top" >
&LT;TD class=t width=32%><b>adarray<br>
</B> (not applicable to ADOX.) ) </TD>
&LT;TD class=t width=13%>0x2000
<p class=t></p>
</TD>
&LT;TD class=t width=55%> A flag value, usually combined with another data type constant, indicating an array of that data type. </TD>
</TR>

&LT;TR valign= "Top" >
&LT;TD class=t width=32%><b>adbigint</b>
<p class=t></p>
</TD>
&LT;TD class=t width=13%>20</td>
The &LT;TD class=t width=55%> indicates a eight-byte signed integer (DBTYPE_I8). </TD>
</TR>

&LT;TR valign= "Top" >
&LT;TD class=t width=32%><b>adbinary</b>
<p class=t></p>
</TD>
&LT;TD class=t width=13%>128</td>
&LT;TD class=t width=55%> indicates a binary value (dbtype_bytes). </TD>
</TR>

&LT;TR valign= "Top" >
&LT;TD class=t width=32%><b>adboolean</b>
<p class=t></p>
</TD>
&LT;TD class=t width=13%>11</td>
&LT;TD class=t width=55%> indicates a Boolean value (Dbtype_bool). </TD>
</TR>

&LT;TR valign= "Top" >
&LT;TD class=t width=32%><b>adbstr</b>
<p class=t></p>
</TD>
&LT;TD class=t width=13%>8</td>
&LT;TD class=t width=55%> indicates a Null-terminated string (Unicode) (DBTYPE_BSTR). </TD>
</TR>

&LT;TR valign= "Top" >
&LT;TD class=t width=32%><b>adchapter</b>
<p class=t></p>
</TD>
&LT;TD class=t width=13%>136</td>
The &LT;TD class=t width=55%> indicates a four-byte subset value that identifies the child <a href= "mddefrowset.htm" > Rows (dbtype_hchapter) in the rowset </A>. </TD>
</TR>

&LT;TR valign= "Top" >
&LT;TD class=t width=32%><b>adchar</b>
<p class=t></p>
</TD>
&LT;TD class=t width=13%>129</td>
&LT;TD class=t width=55%> indicates a string value (DBTYPE_STR). </TD>
</TR>

&LT;TR valign= "Top" >
&LT;TD class=t width=32%><b>adcurrency</b>
<p class=t></p>
</TD>
&LT;TD class=t width=13%>6</td>
&LT;TD class=t width=55%> indicates a currency value (DBTYPE_CY). Currency is a fixed-point number with four digits to the right of the decimal point. This value is stored as a eight-byte, signed integer range of 10,000. </TD>
</TR>

&LT;TR valign= "Top" >
&LT;TD class=t width=32%><b>addate</b>
<p class=t></p>
</TD>
&LT;TD class=t width=13%>7</td>
&LT;TD class=t width=55%> indicates a date value (DBTYPE_DATE). The date is saved as a double, and the integer portion of the number is the number of days from December 30, 1899, and the decimal part is the fragment time of the day. </TD>
</TR>

&LT;TR valign= "Top" >
&LT;TD class=t width=32%><b>addbdate</b>
<p class=t></p>
</TD>
&LT;TD class=t width=13%>133</td>
&LT;TD class=t width=55%> indicates a date value (YYYYMMDD) (dbtype_dbdate). </TD>
</TR>

&LT;TR valign= "Top" >
&LT;TD class=t width=32%><b>addbtime</b>
<p class=t></p>
</TD>
&LT;TD class=t width=13%>134</td>
&LT;TD class=t width=55%> indicates a time value (HHMMSS) (dbtype_dbtime). </TD>
</TR>

&LT;TR valign= "Top" >
&LT;TD class=t width=32%><b>addbtimestamp</b>
<p class=t></p>
</TD>
&LT;TD class=t width=13%>135</td>
&LT;TD class=t width=55%> indicates a date/time stamp (YYYYMMDDHHMMSS plus One-zero decimal) (Dbtype_dbtimestamp). </TD>
</TR>

&LT;TR valign= "Top" >
&LT;TD class=t width=32%><b>addecimal</b>
<p class=t></p>
</TD>
&LT;TD class=t width=13%>14</td>
The &LT;TD class=t width=55%> indicates an exact numeric value (DBTYPE_DECIMAL) with fixed precision and range. </TD>
</TR>

&LT;TR valign= "Top" >
&LT;TD class=t width=32%><b>addouble</b>
<p class=t></p>
</TD>
&LT;TD class=t width=13%>5</td>
&LT;TD class=t width=55%> indicates a double-precision floating-point value (DBTYPE_R8). </TD>
</TR>

&LT;TR valign= "Top" >
&LT;TD class=t width=32%><b>adempty</b>
<p class=t></p>
</TD>
&LT;TD class=t width=13%>0</td>
&LT;TD class=t width=55%> Specifies no value (dbtype_empty). </TD>
</TR>

&LT;TR valign= "Top" >
&LT;TD class=t width=32%><b>aderror</b>
<p class=t></p>
</TD>
&LT;TD class=t width=13%>10</td>
The &LT;TD class=t width=55%> indicates a 32-bit error code (DBTYPE_ERROR). </TD>
</TR>

&LT;TR valign= "Top" >
&LT;TD class=t width=32%><b>adfiletime</b>
<p class=t></p>
</TD>
&LT;TD class=t width=13%>64</td>
The &LT;TD class=t width=55%> indicates a 64-bit value that represents the number of 100 One-zero-second intervals (dbtype_filetime) Starting January 1, 1601. </TD>
</TR>

&LT;TR valign= "Top" >
&LT;TD class=t width=32%><b>adguid</b>
<p class=t></p>
</TD>
&LT;TD class=t width=13%>72</td>
The &LT;TD class=t width=55%> indicates a globally unique identifier (GUID) (DBTYPE_GUID). </TD>
</TR>

&LT;TR valign= "Top" >
&LT;TD class=t width=32%><b>adidispatch</b>
<p class=t></p>
</TD>
&LT;TD class=t width=13%>9</td>
&LT;TD class=t width=55%> indicates pointers to <B>IDispatch</B> interfaces on COM objects (Dbtype_idispatch).
<p class=t><b> Note </b>ado does not currently support this type of data. Using it can lead to unpredictable results. </P>
</TD>
</TR>

&LT;TR valign= "Top" >
&LT;TD class=t width=32%><b>adinteger</b>
<p class=t></p>
</TD>
&LT;TD class=t width=13%>3</td>
The &LT;TD class=t width=55%> indicates a four-byte signed integer (DBTYPE_I4). </TD>
</TR>

&LT;TR valign= "Top" >
&LT;TD class=t width=32%><b>adiunknown</b>
<p class=t></p>
</TD>
&LT;TD class=t width=13%>13</td>
&LT;TD class=t width=55%> indicates pointers to <B>IUnknown</B> interfaces on COM objects (Dbtype_iunknown).
<p class=t><b> Note </b>ado does not currently support this type of data. Using it can lead to unpredictable results. </P>
</TD>
</TR>

&LT;TR valign= "Top" >
&LT;TD class=t width=32%><b>adlongvarbinary</b>
<p class=t></p>
</TD>
&LT;TD class=t width=13%>205</td>
&LT;TD class=t width=55%> indicates a long Binary value (<B>Parameter</B> object only). </TD>
</TR>

&LT;TR valign= "Top" >
&LT;TD class=t width=32%><b>adlongvarchar</b>
<p class=t></p>
</TD>
&LT;TD class=t width=13%>201</td>
&LT;TD class=t width=55%> indicates a long string value (<B>Parameter</B> object only). </TD>
</TR>

&LT;TR valign= "Top" >
&LT;TD class=t width=32%><b>adlongvarwchar</b>
<p class=t></p>
</TD>
&LT;TD class=t width=13%>203</td>
&LT;TD class=t width=55%> indicates a null-terminated long Unicode String value (<B>Parameter</B> object only). </TD>
</TR>

&LT;TR valign= "Top" >
&LT;TD class=t width=32%><b>adnumeric</b>
<p class=t></p>
</TD>
&LT;TD class=t width=13%>131</td>
The &LT;TD class=t width=55%> indicates an exact numeric value (dbtype_numeric) with fixed precision and range. </TD>
</TR>

&LT;TR valign= "Top" >
&LT;TD class=t width=32%><b>adpropvariant</b>
<p class=t></p>
</TD>
&LT;TD class=t width=13%>138</td>
&LT;TD class=t width=55%> indicates a automation propvariant (dbtype_prop_variant). </TD>
</TR>

&LT;TR valign= "Top" >
&LT;TD class=t width=32%><b>adsingle</b>
<p class=t></p>
</TD>
&LT;TD class=t width=13%>4</td>
&LT;TD class=t width=55%> indicates a single-precision floating-point value (DBTYPE_R4). </TD>
</TR>

&LT;TR valign= "Top" >
&LT;TD class=t width=32%><b>adsmallint</b>
<p class=t></p>
</TD>
&LT;TD class=t width=13%>2</td>
&LT;TD class=t width=55%> indicates a two-byte signed integer (DBTYPE_I2). </TD>
</TR>

&LT;TR valign= "Top" >
&LT;TD class=t width=32%><b>adtinyint</b>
<p class=t></p>
</TD>
&LT;TD class=t width=13%>16</td>
The &LT;TD class=t width=55%> indicates a single byte signed integer (DBTYPE_I1). </TD>
</TR>

&LT;TR valign= "Top" >
&LT;TD class=t width=32%><b>adunsignedbigint</b>
<p class=t></p>
</TD>
&LT;TD class=t width=13%>21</td>
The &LT;TD class=t width=55%> indicates a eight-byte unsigned integer (DBTYPE_UI8). </TD>
</TR>

&LT;TR valign= "Top" >
&LT;TD class=t width=32%><b>adunsignedint</b>
<p class=t></p>
</TD>
&LT;TD class=t width=13%>19</td>
The &LT;TD class=t width=55%> indicates a four-byte unsigned integer (DBTYPE_UI4). </TD>
</TR>

&LT;TR valign= "Top" >
&LT;TD class=t width=32%><b>adunsignedsmallint</b>
<p class=t></p>
</TD>
&LT;TD class=t width=13%>18</td>
&LT;TD class=t width=55%> indicates a two-byte unsigned integer (DBTYPE_UI2). </TD>
</TR>

&LT;TR valign= "Top" >
&LT;TD class=t width=32%><b>adunsignedtinyint</b>
<p class=t></p>
</TD>
&LT;TD class=t width=13%>17</td>
The &LT;TD class=t width=55%> indicates a single-byte unsigned integer (DBTYPE_UI1). </TD>
</TR>

&LT;TR valign= "Top" >
&LT;TD class=t width=32%><b>aduserdefined</b>
<p class=t></p>
</TD>
&LT;TD class=t width=13%>132</td>
&LT;TD class=t width=55%> Indicates a user-defined variable (DBTYPE_UDT). </TD>
</TR>

&LT;TR valign= "Top" >
&LT;TD class=t width=32%><b>advarbinary</b>
<p class=t></p>
</TD>
&LT;TD class=t width=13%>204</td>
&LT;TD class=t width=55%> indicates a binary value (<B>Parameter</B> object only). </TD>
</TR>

&LT;TR valign= "Top" >
&LT;TD class=t width=32%><b>advarchar</b>
<p class=t></p>
</TD>
&LT;TD class=t width=13%>200</td>
&LT;TD class=t width=55%> indicates a string value (<B>Parameter</B> object only). </TD>
</TR>

&LT;TR valign= "Top" >
&LT;TD class=t width=32%><b>advariant</b>
<p class=t></p>
</TD>
&LT;TD class=t width=13%>12</td>
&LT;TD class=t width=55%> indicates a automation <B>Variant</B> (dbtype_variant).
<p class=t><b> Note </b>ado does not currently support this type of data. Using it can lead to unpredictable results. </P>
</TD>
</TR>

&LT;TR valign= "Top" >
&LT;TD class=t width=32%><b>advarnumeric</b>
<p class=t></p>
</TD>
&LT;TD class=t width=13%>139</td>
&LT;TD class=t width=55%> indicates a numeric value (limited to <B>Parameter</B> objects). </TD>
</TR>

&LT;TR valign= "Top" >
&LT;TD class=t width=32%><b>advarwchar</b>
<p class=t></p>
</TD>
&LT;TD class=t width=13%>202</td>
&LT;TD class=t width=55%> indicates a Null-terminated Unicode string (<B>Parameter</B> object only). </TD>
</TR>

&LT;TR valign= "Top" >
&LT;TD class=t width=32%><b>adwchar</b>
<p class=t></p>
</TD>
&LT;TD class=t width=13%>130</td>
&LT;TD class=t width=55%> indicates a Null-terminated Unicode string (DBTYPE_WSTR). </TD>
</TR>
</TABLE>
</body>

in an existing table, create a field.
Copy Code code as follows:

<%
dbs= "Data source=" +server.mappath ("Database.mdb") + "; provider=microsoft.jet.oledb.4.0; "
Set Conn=server.createobject ("Adodb.connection")
Conn.Open DBS
Set Cat =server.createobject ("ADOX.") Catalog ")
Set Cat. ActiveConnection = conn
Set Tbl=cat.tables ("BBS")
Set objcolumn = Server.CreateObject ("ADOX. Column ")
Set Objcolumn.parentcatalog = Cat
Objcolumn.name = "Time1"
Objcolumn.type = "130"
objcolumn.attributes=2
Tbl.columns.append Objcolumn

Set objtable = Nothing
Set objcat = Nothing

%>


Delete fields and modify fields
Copy Code code as follows:

<%
dbs= "Data source=" +server.mappath ("Database.mdb") + "; provider=microsoft.jet.oledb.4.0; "
Set Conn=server.createobject ("Adodb.connection")
Conn.Open DBS
Set Cat =server.createobject ("ADOX.") Catalog ")
Set Cat. ActiveConnection = conn
Set Tbl=cat.tables ("BBS")
Tbl.columns.delete "Time"

Set Field=tbl.columns ("Time2")

Field.name= "Time"
%>


Creating a Database File
Copy Code code as follows:

<% @LANGUAGE = "VBSCRIPT" codepage= "936"%>
<%
Option Explicit
Dim DatabaseName ' defines the database name
Databasename= "Database.mdb" database name
Dim DatabasePath ' Defines the database store path
Databasepath= "E:\ Zhang Wei \ module development \ News module \" ' Database absolute path
Dim databasever ' defines database version 2000 or 97
Databasever = "2000"

Function Createdfile (Filepath,filename,ver)
Dim Ca,dbver
Select Case ver
Case "97"
Dbver = "3.51"
Case "2000"
Dbver = "4.0"
End Select
If Dbver <> "" Then
Set Ca = Server.CreateObject ("ADOX.") Catalog ")
Call Ca.create ("Provider=microsoft.jet.oledb." & Dbver & ";D ata source=" & filepath & filename)
End If
End Function

Createdfile databasepath,databasename,databasever ' CREATE database

%>

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.