你说的是自动建立数据库吗?我以前用的是SYBASE,不过我想应该差不多吧。找到建立数据库的文件(系统文件之类的),把它的内容拷贝到一个文本里面,用ADO来读取文本文件。你可以到数据库板块去问问,SQL SERVER是否有建立数据库的文件。。

解决方案 »

  1.   

    http://expert.csdn.net/Expert/topic/1068/1068439.xml?temp=.1340753
      

  2.   

    先把连接建立到master上,然后Create Database,再把连接的DefaultDatabase改成新建的数据库,就可以用Create Table了。
      

  3.   

    如何把连接的DefaultDatabase改成新建的数据库,vb提示对象已经打开
      

  4.   

    dim con as adodb.connection
    dim sql as string
    set con=new connection
    con.connectionstring="provider=msdasql;driver=sql server;server=" & ServerName & ";uid=" & Uid & ";pwd=" & Pwd & ";database=master;"
    …………
    con.open'创建数据库
    sql="CREATE DATABASE DBname…………"
    con.execute sql'创建表格
    sql="use DBname Create Table TableName…………"
    con.execute sql'创建视图
    sql="use DBname Create View ViewName…………"
    con.execute sql…………'连接到新建的数据库
    Set con=new connection
    con.connectionstring="provider=msdasql;driver=sql server;server=" & ServerName & ";uid=" & Uid & ";pwd=" & Pwd & ";database=DBname;"
    …………
    con.open
      

  5.   

    ado是没有办法建立数据库和表的,如果你要通过程序来建立数据库和表的话就要用DMO对象,这样就可以了.
      

  6.   

    写错了,呵呵,ADO对象可以建立表,但比较繁,用DMO就比较方便了
      

  7.   

    Option ExplicitDim oSQLServer As New SQLDMO.SQLServer
    Private Sub cmdCreateDB_Click()
        
        Dim oDatabase As New SQLDMO.Database
        Dim oDBFile As New SQLDMO.DBFile
        Dim oLogFile As New SQLDMO.LogFile
        
        Dim sDatabaseName As String
        Dim sDBFilePath As String
        
        On Error GoTo CreateDB_Err
       
        'Input the database name
        sDatabaseName = InputBox("Enter the new database name", _
            "New Database")
        
        ' Make sure that the database name isn't already used
        On Error Resume Next
        If oSQLServer.Databases(sDatabaseName).Name = "" Then
        End If
        
        If Err = 0 Then
            MsgBox sDatabaseName & " already exists!"
            GoTo CreateDB_Exit
        Else
            On Error GoTo CreateDB_Err
        End If
        
        'Set the object's database name
        oDatabase.Name = sDatabaseName
        
        'Input the path for the data and log files
        sDBFilePath = InputBox("Enter the path for data and log files", _
          "New Database", _
          "c:\Program Files\Microsoft SQL Server\MSSQL\Data\" _
          & sDatabaseName)
        
       'Set the properties of the DBFile object
        oDBFile.Name = sDatabaseName & ".mdf"
        oDBFile.PhysicalName = sDBFilePath & ".mdf"
        
       'Add the DBFile object to the collection
        oDatabase.FileGroups("PRIMARY").DBFiles.Add oDBFile
        
       'Set the properties of the LogFile object
        oLogFile.Name = sDatabaseName & ".ldf"
        oLogFile.PhysicalName = sDBFilePath & ".ldf"
       
       'Add the LogFile object to the collection
        oDatabase.TransactionLog.LogFiles.Add oLogFile
      
       'Add the new DB object to the databases collection
        oSQLServer.Databases.Add oDatabase
      
         
    CreateDB_Exit:
        On Error Resume Next
        
        Set oLogFile = Nothing
        Set oDBFile = Nothing
        Set oDatabase = Nothing
        
        MousePointer = vbDefault    Exit SubCreateDB_Err:
        SQLDMOError
        Resume CreateDB_ExitEnd Sub
      

  8.   

    建立数据表(指定数据表是属于哪一个数据库的,不管当前打开的连接是连接到哪一个数据库都无所谓):
    create databasename.dbo.tablename(col1 char(10),col2 char(20)...)
      

  9.   

    更正:
    create table databasename.dbo.tablename(col1 char(10),col2 char(20)...)