创建数据表
2006-6-30 7:56:47 作者:模板天下收集整理 来源:未知 网友评论 0 条
论坛
'**************************************************
'[创建数据表]
'函数名:CreatTable
'作 用:创建数据表
'参 数:ConnStrs ---- 数据库链接字串
'参 数:Tabnamestr ---- 数据表名称
'参 数:CvArrstr ---- 字段表 (写法: Fname1#Type#Len#Defvalue|Fname1#Type#Len#Defvalue|...) 最后一个不要写“|”
'参 数:SqlType ---- Sql语句类型 (0 Access 1 Mssqlserver)
' Fname,Type,Len,Defvalue 说明:字段名称,字段类型,字段长度,默认值
'字段类型 Type C/c 字符 T/t 文本 I/i 二进制 D/d 日期 M/m 关键字(字符型) A/a 关键字自动编号(数值型) N/n 数值(float) Z/z 数值(int)
'返回值:如果建立成功返回 True 否则 False
'示 例:CreatTable(basicDB(3),"cs","fa#t##|fb#c#20#a|fc#n##5",0)
'**************************************************
Public Function CreatTable(ByVal ConnStrs,ByVal Tabnamestr,ByVal CvArrstr,ByVal SqlType)
CreatTable=False
On Error GoTo 0
On Error Resume Next
Dim filsarry,NeFilarry,Filstr,spfstr,templx,def_kh_l,def_kh_r,TempSqlStr
def_kh_l=""
def_kh_r=""
Filstr=""
spfstr=""
TempSqlStr=""
filsarry=Split(CvArrstr,"|")
For ai = LBound(filsarry) To UBound(filsarry)
NeFilarry=Split(filsarry(ai),"#")
templx=""
If UCase(NeFilarry(1))="C" Then templx="varchar(" & NeFilarry(2) & ")"
If UCase(NeFilarry(1))="T" Then templx="TEXT"
If UCase(NeFilarry(1))="I" Then templx="image"
If UCase(NeFilarry(1))="D" Then templx="datetime"
If UCase(NeFilarry(1))="M" Then templx="varchar(" & NeFilarry(2) & ") NOT NULL PRIMARY KEY"
If UCase(NeFilarry(1))="A" Then templx="Int IDENTITY (1,1) NOT NULL PRIMARY KEY"
If UCase(NeFilarry(1))="N" Then templx="Float"
If UCase(NeFilarry(1))="Z" Then templx="Int"
If SqlType =1 Then
def_kh_l="('"
def_kh_r="')"
End If
If Trim(NeFilarry(3))<>"" Then templx=templx &" DEFAULT " & def_kh_l & Trim(NeFilarry(3)) & def_kh_r
If ai<>UBound(filsarry) Then
spfstr= spfstr & "[" & NeFilarry(0) & "] " & templx &","
Else
spfstr= spfstr & "[" & NeFilarry(0) & "] " & templx
End If
Next
TempSqlStr="CREATE TABLE ["&Trim(Tabnamestr)&"] (" & spfstr & ")"
set fu_Conn=server.createobject("ADODB.Connection")
fu_Conn.open ConnStrs
fu_Conn.Execute TempSqlStr
fu_Conn.Close
Set fu_Conn=Nothing
If Err.Number = 0 Then
CreatTable=True
End If
On Error GoTo 0
End Function
>> 相关文章