回复 12楼 recool
帮你弄了个可以自动创建sql数据库和数据表的,在我的sql2000上调试成功
现贴出在sql server中创建数据库和数据表的代码,供各爱好者参考。
Private Sub Form_Load()
Dim con As New ADODB.Connection, SQL As String, rst As New Recordset
On Error Resume Next
'错误处理
'以下是自动创建数据库和数据表的代码,如果存在不会重复创建的
SQL = " Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog"
con.Open SQL
SQL = "CREATE DATABASE 工作安排系统"
con.Execute SQL
'新建数据库,如果已经有该数据库则出错跳过
con.Close
SQL = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=工作安排系统"
con.Open SQL
SQL = "CREATE TABLE [dbo].[安排信息表] ("
SQL = SQL & "[name] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NOT NULL ,"
SQL = SQL & "[ftime] [datetime] NOT NULL ,"
SQL = SQL & "[etime] [datetime] NOT NULL ,"
SQL = SQL & "[content] [text] COLLATE Chinese_PRC_CI_AS NOT NULL ,"
SQL = SQL & "[task] [text] COLLATE Chinese_PRC_CI_AS NULL ,"
SQL = SQL & "[status] [char] (6) COLLATE Chinese_PRC_CI_AS NOT NULL "
SQL = SQL & ") ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]"
con.Execute SQL
'新建表1,如果存在该数据表则出错跳过
SQL = "CREATE TABLE [dbo].[日志信息表] ("
SQL = SQL & "[id] [numeric](18, 0) IDENTITY (1, 1) NOT NULL ,"
SQL = SQL & "[name] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NOT NULL ,"
SQL = SQL & "[type] [char] (6) COLLATE Chinese_PRC_CI_AS NOT NULL ,"
SQL = SQL & "[datet] [datetime] NOT NULL ,"
SQL = SQL & "[remark] [text] COLLATE Chinese_PRC_CI_AS NULL "
SQL = SQL & ") ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]"
con.Execute SQL
'新建表2,如果存在该数据表则出错跳过
con.Close
End Sub