為何我新建立的數据庫不能加入記錄? 怎樣在新建數据庫時候設定?
以下是新建數据庫﹕
Public Sub newfile()
CommonDialog1.DialogTitle = "Please enter the new database name"
CommonDialog1.Filter = "Access database file MDB|*.mdb"
CommonDialog1.FileName = ""
CommonDialog1.InitDir = App.Path
CommonDialog1.ShowSave
dataname = CommonDialog1.FileName
If dataname = "" Then
Exit Sub
Else
cat.Create "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & dataname
Image1.Visible = False
DataGrid1.Visible = True
End If
End Sub以下是新建立數据表:
newtable = InputBox("Please enter the new table name", "New table")
cat.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & dataname
newtb.Name = newtable
newtb.Columns.Append "NO"
cat.Tables.Append newtb
cat.Tables.Refresh
DataGrid1.Refresh
list1.additem newtable
list1.ListIndex = 0
以下是新建數据庫﹕
Public Sub newfile()
CommonDialog1.DialogTitle = "Please enter the new database name"
CommonDialog1.Filter = "Access database file MDB|*.mdb"
CommonDialog1.FileName = ""
CommonDialog1.InitDir = App.Path
CommonDialog1.ShowSave
dataname = CommonDialog1.FileName
If dataname = "" Then
Exit Sub
Else
cat.Create "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & dataname
Image1.Visible = False
DataGrid1.Visible = True
End If
End Sub以下是新建立數据表:
newtable = InputBox("Please enter the new table name", "New table")
cat.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & dataname
newtb.Name = newtable
newtb.Columns.Append "NO"
cat.Tables.Append newtb
cat.Tables.Refresh
DataGrid1.Refresh
list1.additem newtable
list1.ListIndex = 0
Set Wrk = DBEngine.Workspaces(0)
Set dbs = Wrk.CreateDatabase(App.Path & "\" & DatabaseName & TableName & "Outputtemp.mdb", dbLangChineseSimplified)
Set tdfNew = dbs.CreateTableDef(TableName) tdfNew.Fields.Append tdfNew.CreateField(Col1, dbText)
tdfNew.Fields.Append tdfNew.CreateField(Col2, dbText)
tdfNew.Fields.Append tdfNew.CreateField(Col3, dbText)
tdfNew.Fields.Append tdfNew.CreateField(Col4, dbText)
dbs.TableDefs.Append tdfNew