Introduction to ASP Programming (21): DAO SQL Build database table

Source: Internet
Author: User
Tags datetime manual integer key sql
Programming | data | Database are you satisfied with the database you designed? Are you sure you don't want to deal with it? For example, create a new database table, such as creating or modifying a field ... Of course, these are all part of the design database.

So, your normal operation is not to download the database to the local computer, and then open it to modify, and then upload it up? Ten to one,-_-!.

Now, you can contact with the information about this, after all, the function of the Code is for manual operation to save a lot of time. But is the code generation still not manual? Hehe:)

1, set up database file Cnbruce.mdb (no table design)

To build the code for the database:


<%
Option Explicit
Dim DatabaseName ' defines the database name
Databasename= "Cnbruce.mdb" database name
Dim DatabasePath ' Defines the database store path
Databasepath= "e:\cnbruce\database\" Database absolute path
Dim databasever ' defines database version 2000 or 97
Databasever = "2000"

Function Createdfile (Filepath,filename,ver)

Dim Cnbruce,dbver
Select Case ver
Case "97"
Dbver = "3.51"
Case "2000"
Dbver = "4.0"
End Select

If Dbver <> "" Then
Set cnbruce = Server.CreateObject ("ADOX. Catalog ")
Call Cnbruce. Create ("Provider=microsoft.jet.oledb." & Dbver & ";D ata source=" & filepath & filename)
End If

End Function

Call Createdfile (databasepath,databasename,databasever) ' Create a database
%>




So, let's look at how to design a new database table.

2, establish the database connection file conn.asp



<%
Db_path = "Cnbruce.mdb"
Set conn= Server.CreateObject ("ADODB.") Connection ")
ConnStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data source=" &server.mappath (Db_path)
Conn. Open ConnStr
%>




3, set up a new database table of the program page addtable.asp



<!--#include file= "conn.asp"-->

<%
Set rs = Server.CreateObject ("ADODB.") Recordset ")
sql = "CREATE TABLE aboutme (ID integer primary key,name text,birthday datetime)"
Rs. Open sql,conn,2,3
%>
The database table file is established.




CREATE table Aboutme (ID integer primary key,name text,birthday datetime)
Create a new table Aboutme, design a field with ID (primary key), name (memo), Birthday (time date)



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.