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%>
<TR valign= "Top" >
<th Width=32%> Constants </TH>
<th width=13%> Value </TH>
<th width=55%> Description </TH>
</TR>
<TR valign= "Top" >
<TD class=t width=32%><b>adarray<br>
</B> (not applicable to ADOX.) ) </TD>
<TD class=t width=13%>0x2000
<p class=t></p>
</TD>
<TD class=t width=55%> A flag value, usually combined with another data type constant, indicating an array of that data type. </TD>
</TR>
<TR valign= "Top" >
<TD class=t width=32%><b>adbigint</b>
<p class=t></p>
</TD>
<TD class=t width=13%>20</td>
The <TD class=t width=55%> indicates a eight-byte signed integer (DBTYPE_I8). </TD>
</TR>
<TR valign= "Top" >
<TD class=t width=32%><b>adbinary</b>
<p class=t></p>
</TD>
<TD class=t width=13%>128</td>
<TD class=t width=55%> indicates a binary value (dbtype_bytes). </TD>
</TR>
<TR valign= "Top" >
<TD class=t width=32%><b>adboolean</b>
<p class=t></p>
</TD>
<TD class=t width=13%>11</td>
<TD class=t width=55%> indicates a Boolean value (Dbtype_bool). </TD>
</TR>
<TR valign= "Top" >
<TD class=t width=32%><b>adbstr</b>
<p class=t></p>
</TD>
<TD class=t width=13%>8</td>
<TD class=t width=55%> indicates a Null-terminated string (Unicode) (DBTYPE_BSTR). </TD>
</TR>
<TR valign= "Top" >
<TD class=t width=32%><b>adchapter</b>
<p class=t></p>
</TD>
<TD class=t width=13%>136</td>
The <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>
<TR valign= "Top" >
<TD class=t width=32%><b>adchar</b>
<p class=t></p>
</TD>
<TD class=t width=13%>129</td>
<TD class=t width=55%> indicates a string value (DBTYPE_STR). </TD>
</TR>
<TR valign= "Top" >
<TD class=t width=32%><b>adcurrency</b>
<p class=t></p>
</TD>
<TD class=t width=13%>6</td>
<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>
<TR valign= "Top" >
<TD class=t width=32%><b>addate</b>
<p class=t></p>
</TD>
<TD class=t width=13%>7</td>
<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>
<TR valign= "Top" >
<TD class=t width=32%><b>addbdate</b>
<p class=t></p>
</TD>
<TD class=t width=13%>133</td>
<TD class=t width=55%> indicates a date value (YYYYMMDD) (dbtype_dbdate). </TD>
</TR>
<TR valign= "Top" >
<TD class=t width=32%><b>addbtime</b>
<p class=t></p>
</TD>
<TD class=t width=13%>134</td>
<TD class=t width=55%> indicates a time value (HHMMSS) (dbtype_dbtime). </TD>
</TR>
<TR valign= "Top" >
<TD class=t width=32%><b>addbtimestamp</b>
<p class=t></p>
</TD>
<TD class=t width=13%>135</td>
<TD class=t width=55%> indicates a date/time stamp (YYYYMMDDHHMMSS plus One-zero decimal) (Dbtype_dbtimestamp). </TD>
</TR>
<TR valign= "Top" >
<TD class=t width=32%><b>addecimal</b>
<p class=t></p>
</TD>
<TD class=t width=13%>14</td>
The <TD class=t width=55%> indicates an exact numeric value (DBTYPE_DECIMAL) with fixed precision and range. </TD>
</TR>
<TR valign= "Top" >
<TD class=t width=32%><b>addouble</b>
<p class=t></p>
</TD>
<TD class=t width=13%>5</td>
<TD class=t width=55%> indicates a double-precision floating-point value (DBTYPE_R8). </TD>
</TR>
<TR valign= "Top" >
<TD class=t width=32%><b>adempty</b>
<p class=t></p>
</TD>
<TD class=t width=13%>0</td>
<TD class=t width=55%> Specifies no value (dbtype_empty). </TD>
</TR>
<TR valign= "Top" >
<TD class=t width=32%><b>aderror</b>
<p class=t></p>
</TD>
<TD class=t width=13%>10</td>
The <TD class=t width=55%> indicates a 32-bit error code (DBTYPE_ERROR). </TD>
</TR>
<TR valign= "Top" >
<TD class=t width=32%><b>adfiletime</b>
<p class=t></p>
</TD>
<TD class=t width=13%>64</td>
The <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>
<TR valign= "Top" >
<TD class=t width=32%><b>adguid</b>
<p class=t></p>
</TD>
<TD class=t width=13%>72</td>
The <TD class=t width=55%> indicates a globally unique identifier (GUID) (DBTYPE_GUID). </TD>
</TR>
<TR valign= "Top" >
<TD class=t width=32%><b>adidispatch</b>
<p class=t></p>
</TD>
<TD class=t width=13%>9</td>
<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>
<TR valign= "Top" >
<TD class=t width=32%><b>adinteger</b>
<p class=t></p>
</TD>
<TD class=t width=13%>3</td>
The <TD class=t width=55%> indicates a four-byte signed integer (DBTYPE_I4). </TD>
</TR>
<TR valign= "Top" >
<TD class=t width=32%><b>adiunknown</b>
<p class=t></p>
</TD>
<TD class=t width=13%>13</td>
<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>
<TR valign= "Top" >
<TD class=t width=32%><b>adlongvarbinary</b>
<p class=t></p>
</TD>
<TD class=t width=13%>205</td>
<TD class=t width=55%> indicates a long Binary value (<B>Parameter</B> object only). </TD>
</TR>
<TR valign= "Top" >
<TD class=t width=32%><b>adlongvarchar</b>
<p class=t></p>
</TD>
<TD class=t width=13%>201</td>
<TD class=t width=55%> indicates a long string value (<B>Parameter</B> object only). </TD>
</TR>
<TR valign= "Top" >
<TD class=t width=32%><b>adlongvarwchar</b>
<p class=t></p>
</TD>
<TD class=t width=13%>203</td>
<TD class=t width=55%> indicates a null-terminated long Unicode String value (<B>Parameter</B> object only). </TD>
</TR>
<TR valign= "Top" >
<TD class=t width=32%><b>adnumeric</b>
<p class=t></p>
</TD>
<TD class=t width=13%>131</td>
The <TD class=t width=55%> indicates an exact numeric value (dbtype_numeric) with fixed precision and range. </TD>
</TR>
<TR valign= "Top" >
<TD class=t width=32%><b>adpropvariant</b>
<p class=t></p>
</TD>
<TD class=t width=13%>138</td>
<TD class=t width=55%> indicates a automation propvariant (dbtype_prop_variant). </TD>
</TR>
<TR valign= "Top" >
<TD class=t width=32%><b>adsingle</b>
<p class=t></p>
</TD>
<TD class=t width=13%>4</td>
<TD class=t width=55%> indicates a single-precision floating-point value (DBTYPE_R4). </TD>
</TR>
<TR valign= "Top" >
<TD class=t width=32%><b>adsmallint</b>
<p class=t></p>
</TD>
<TD class=t width=13%>2</td>
<TD class=t width=55%> indicates a two-byte signed integer (DBTYPE_I2). </TD>
</TR>
<TR valign= "Top" >
<TD class=t width=32%><b>adtinyint</b>
<p class=t></p>
</TD>
<TD class=t width=13%>16</td>
The <TD class=t width=55%> indicates a single byte signed integer (DBTYPE_I1). </TD>
</TR>
<TR valign= "Top" >
<TD class=t width=32%><b>adunsignedbigint</b>
<p class=t></p>
</TD>
<TD class=t width=13%>21</td>
The <TD class=t width=55%> indicates a eight-byte unsigned integer (DBTYPE_UI8). </TD>
</TR>
<TR valign= "Top" >
<TD class=t width=32%><b>adunsignedint</b>
<p class=t></p>
</TD>
<TD class=t width=13%>19</td>
The <TD class=t width=55%> indicates a four-byte unsigned integer (DBTYPE_UI4). </TD>
</TR>
<TR valign= "Top" >
<TD class=t width=32%><b>adunsignedsmallint</b>
<p class=t></p>
</TD>
<TD class=t width=13%>18</td>
<TD class=t width=55%> indicates a two-byte unsigned integer (DBTYPE_UI2). </TD>
</TR>
<TR valign= "Top" >
<TD class=t width=32%><b>adunsignedtinyint</b>
<p class=t></p>
</TD>
<TD class=t width=13%>17</td>
The <TD class=t width=55%> indicates a single-byte unsigned integer (DBTYPE_UI1). </TD>
</TR>
<TR valign= "Top" >
<TD class=t width=32%><b>aduserdefined</b>
<p class=t></p>
</TD>
<TD class=t width=13%>132</td>
<TD class=t width=55%> Indicates a user-defined variable (DBTYPE_UDT). </TD>
</TR>
<TR valign= "Top" >
<TD class=t width=32%><b>advarbinary</b>
<p class=t></p>
</TD>
<TD class=t width=13%>204</td>
<TD class=t width=55%> indicates a binary value (<B>Parameter</B> object only). </TD>
</TR>
<TR valign= "Top" >
<TD class=t width=32%><b>advarchar</b>
<p class=t></p>
</TD>
<TD class=t width=13%>200</td>
<TD class=t width=55%> indicates a string value (<B>Parameter</B> object only). </TD>
</TR>
<TR valign= "Top" >
<TD class=t width=32%><b>advariant</b>
<p class=t></p>
</TD>
<TD class=t width=13%>12</td>
<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>
<TR valign= "Top" >
<TD class=t width=32%><b>advarnumeric</b>
<p class=t></p>
</TD>
<TD class=t width=13%>139</td>
<TD class=t width=55%> indicates a numeric value (limited to <B>Parameter</B> objects). </TD>
</TR>
<TR valign= "Top" >
<TD class=t width=32%><b>advarwchar</b>
<p class=t></p>
</TD>
<TD class=t width=13%>202</td>
<TD class=t width=55%> indicates a Null-terminated Unicode string (<B>Parameter</B> object only). </TD>
</TR>
<TR valign= "Top" >
<TD class=t width=32%><b>adwchar</b>
<p class=t></p>
</TD>
<TD class=t width=13%>130</td>
<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
%>