如何在ado里面动态创建数据库和表、字段?

jisheng 2001-05-20 11:28:00
如题。
那位大哥给出好用的源代码
我给他加26分
...全文
60 点赞 收藏 3
写回复
3 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
jisheng 2001-05-31
谢谢啦
回复
guest 2001-05-20
Public Function Creat_Table(data As String, Files As String) As Boolean
'本模块用于从*.sql中导入数据库结构到SQL Server
Dim SQL, Txtline As String

On Error Resume Next
Cn.Close
On Error GoTo Err1
ConSQL Load_ini("服务器名"), Load_ini("用户名"), Load_ini("口令"), data, "Cn"
SQL = " "
Open App.Path & "\log.txt" For Output As #2 ' 打开输出文件。
' 将错误数据写入文件。

Open App.Path & Files For Input As #1 ' 打开SQL文件。
Do While Not EOF(1)
Line Input #1, Textline
If Not (Trim(Textline) = "GO") Then
SQL = SQL & Textline & Chr(13)
Else
Cn.Execute SQL 'Mid(SQL, InStr(SQL, "C"))
SQL = " "
End If
Loop
Close #1
Close #2
'If Creat_Table = False Then
' Shell App.Path & "\log.txt"
'End If

Exit Function
Err1:
Print #2, "This is a Error !"
Print #2, Err.Description
Print #2, Err.Number
Print #2, "**********"
Creat_Table = False
Resume Next
End Function
回复
guest 2001-05-20
通用模块VB的
paths 为服务器上的地址
Public Function Creat_Database(Paths As String, Files As String) As Boolean
'在SQLserver 中建立一个库
Dim SQL$
SQL = ""
SQL = SQL & "CREATE DATABASE " & Files
SQL = SQL & " ON "
SQL = SQL & "( NAME = '" & Files & "_dat',"
SQL = SQL & " FILENAME = '" & Paths & Files & "_dat.jdt',"
SQL = SQL & " SIZE = 10MB,"
SQL = SQL & " MAXSIZE = 50MB,"
SQL = SQL & " FILEGROWTH = 5MB )"
SQL = SQL & "LOG ON"
SQL = SQL & "( NAME = 'Sales_log',"
SQL = SQL & " FILENAME = '" & Paths & Files & "_log.jdt',"
SQL = SQL & " SIZE = 5MB,"
SQL = SQL & " MAXSIZE = 25MB,"
SQL = SQL & " FILEGROWTH = 5MB )"
'On Error GoTo Err1
Cm.Execute SQL
Creat_Database = True
Exit Function
Err1:
Creat_Database = False
End Function
回复
相关推荐
发帖

1188

社区成员

VB 数据库(包含打印,安装,报表)
申请成为版主
帖子事件
创建了帖子
2001-05-20 11:28
社区公告
暂无公告