| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 971 人关注过本帖
标题:关于数据写入数据库的问题
只看楼主 加入收藏
libingchao
Rank: 1
等 级:新手上路
威 望:1
帖 子:6
专家分:0
注 册:2020-11-5
结帖率:0
收藏
 问题点数:0 回复次数:0 
关于数据写入数据库的问题
这是我自己编写的创建和写入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
搜索更多相关主题的帖子: Set Sub 写入 End Dim 
2021-02-22 18:55
快速回复:关于数据写入数据库的问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.020078 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved