我是初学者,按照书本上的方法去学习和试验书本内容如下:                        <用代码建立数据库文件>在Visual Basic的应用程序中,还可以通过编写代码来建立一个数据库文件,以及对数据库进行索引、查询等许多操作。这样就需要用到几个心的对象,如“DataBase”、“TableDef”、“Field”等,这些被统称为数据库存取对象 DAO(Data Access Object)。DBEngine是DAO的最高层接口,在它下面可以生成一个Workspace对象**,可以利用某一个Workspace对象的CreateDatabase方法建立心的数据库文件。首先要定义对象变量,例如:dim ws as workspace
dim DB as database '指明用WS代表DBEngine生成的哪个 Workspace 。
set WS=DBEngine.workspace(0)在上列中将工作环境定义为使用 DBEngine 的 Workspace (0) 对象,实际这个对象是缺省值,不定义也将使用该对象,但当使用其他对象时,如 Workspace (1) ,就必须重新定义。利用Workspace的 CreateDatabase方法来创建数据库文件,其语法格式为:Set database = Workspace.CreateDatabase(name,local[,Option])其中,Database 为已定义的数据库类型变量,代表新建立的数据库对象。
Workspace 为已定义 Workspace 类型变量,表示所使用的工作环境,包含新的数据库对象。
name 为将要新建的数据库文件路径和名称。
Local 该表达式用来指定字符串比较的规则,一般按英文字母顺序比较,可以指定为 dbLanggeneral 。
option 该项为可选项,用来指定数据格式的版本及数据库是否解密,一般情况下,可以不指定此项。例如,要在 D 盘 tsgl 目录下建立一个名为 xxjs_book的数据库文件,可采用如下代码来实现:dim WS as Workspace
dim DB as Database
set DB = WS.CreateDatabase("D:\tsgl\xxjs_book",dblanggeneral)******************书本内容结束*********************但是我做了,却提示错误,后来引用了 microsoft DAO 3.6 object library 又提示:对象变量或 With 块变量未设置弄多了,有时候提示 :vb 找不到可安装的 ISAM
希望有人能帮我解决,非常感谢..

解决方案 »

  1.   

    我在D盘新建了一个名为 tsgl的文件夹
    然后我的代码如下:
    Private Sub Command1_Click()
     Dim WS As Workspace
    Dim DB As Database
    Set DB = WS.CreateDatabase("D:\tsgl\xxjs_book", dbLangGeneral)
    End Sub
      

  2.   

    CreateDatabase Method Example'This example uses CreateDatabase to create a new, encrypted Database object.Sub CreateDatabaseX() 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("NewDB.mdb") <> "" Then Kill "NewDB.mdb" ' Create a new encrypted database with the specified 
    ' collating order.
    Set dbsNew = wrkDefault.CreateDatabase("NewDB.mdb", _
    dbLangGeneral, dbEncrypt)With dbsNew
    Debug.Print "Properties of " & .Name
    ' Enumerate the Properties collection of the new 
    ' Database object.
    For Each prpLoop In .Properties
    If prpLoop <> "" Then Debug.Print "    " & _
    prpLoop.Name & " = " & prpLoop
    Next prpLoop
    End With dbsNew.CloseEnd Sub
    建议使用ADO而不再使用DAO