SQL Server: Create Database <DbName>
Access: VB6.0 code:
Function CreateDatabaseX(ByVal Fn As String) As Integer
'Create an Access database function,
'Return value:
'   0 - Successfully
'   1 - File already exist
'   2 - Workspace create error   Dim wrkDefault As Workspace
   Dim dbsNew As Database
   Dim prpLoop As Property
   
   ' Get default Workspace.
   Set wrkDefault = DBEngine.Workspaces(0)   ' Make sure there isn't already a file with the name of
   ' the new database.
   If Dir(Fn) <> "" Then
    CreateDatabaseX = 1
    Exit Function
   End If
   ' Create a new encrypted database with the specified
   ' collating order.
   On Error GoTo CreateError
   Set dbsNew = wrkDefault.CreateDatabase(Fn, _
      dbLangGeneral, dbEncrypt)
   CreateDatabaseX = 0
   
   dbsNew.Close
   Exit Function
   
CreateError:
   CreateDatabaseX = 2
End Function
实际上这些东西在MSDN上都有。

解决方案 »

  1.   

    上面的代码需要在工程的引用里加入 Microsoft DAO 3.6 Object Library,倒不一定是 dao3.6 ,只要是DAO就行了。
      

  2.   

    请问CloneCenter(复制中心) :
       
       能不能用ado来实现啊?
      

  3.   

    用ado更容易了
    用sql语句建立数据库“create database”,然后用connection.execute,或者command提交不就行了
      

  4.   

    但是没有数据库的时候用ADO怎么连接啊?
    尤其是对access要凭空生成mdb文件,怎么做啊?