关于数据写入数据库的问题
这是我自己编写的创建和写入access数据库的程序,可以正常创建,但是无法将数据写入。 请问大神是怎么回事,是哪里有设置的问题吗?求指教Private Sub Command1_Click(Index As Integer)
Select Case Index
Case 0
FileNumber = Format(Now, "yymmddhhmmss")
CreateDatabaseSaveData App.Path & "\DATA\" & FileNumber & "-1" & ".mdb"
Case 1
FillInSaveData App.Path & "\DATA\" & FileNumber & "-1" & ".mdb", CInt(Text1(0).Text), CInt(Text1(1).Text)
End Select
End Sub
Private Sub Form_Load()
If Dir(App.Path & "\DATA", vbDirectory) = "" Then MkDir App.Path & "\DATA"
End Sub
Public Sub FillInSaveData(ByVal Savepath As String, ByVal TestTime As Integer, ByVal Record As Single) ''''''''建立曲线存储
On Error Resume Next
Dim TempDB As Database
Dim TempField As Field
Dim TempRS As Recordset
Set TempDB = OpenDatabase(Savepath)
Set TempRS = TempDB.OpenRecordset("Select * from DataTable")
TempRS.AddNew
TempRS.Fields(0).Value = TestTime
TempRS.Fields(1).Value = Record
TempRS.Update
TempDB.Close
End Sub
Public Sub CreateDatabaseSaveData(ByVal DatabaseName As String) ''''''''''''''''''''''''''''''''''''''写入曲线存储
Dim TempWS As Workspace
Dim TempDB As Database
Dim TempTD As TableDef
Dim TempField As Field
Dim TempRS As Recordset
Dim i As Integer
Set TempWS = DBEngine.Workspaces(0)
Set TempDB = TempWS.CreateDatabase(DatabaseName, dbLangGeneral)
Set TempDB = TempWS.OpenDatabase(DatabaseName)
Set TempTD = TempDB.CreateTableDef("DataTable")
With TempTD
.Fields.Append .CreateField("时间", dbSingle)
.Fields.Append .CreateField("数据", dbSingle)
End With
TempDB.TableDefs.Append TempTD
TempDB.Close
End Sub