VB+数据库的问题????
我用串口接收过来数据,用VB的MSComm控件做接收界面,并且通过串口传过来的数据存储到ACCESS2003建的数据库表格里,请问如何在VB里编程以完成数据自动存储呢?谢谢! --------------------编程问答-------------------- 同问!!先谢谢了 --------------------编程问答-------------------- 也有类似问题 --------------------编程问答-------------------- 最简单的是在mscomm的DataArrival接收事件中直接写保存的代码。每秒钟接收一次,保存一次数据。 --------------------编程问答-------------------- 用Adodc
建个数据库文件Testdata.mdb,建个表,我下面程序中表为data
我生成了20个数据,把它保存到数据库的表data里。
Dim cnn As ADODB.Connection
Dim cmd As ADODB.Command
Dim res As ADODB.Recordset
Public Sub Store()
Dim str As String
Dim sql As String
Dim i As Integer
Dim storestr As String
Dim Strname As String
Dim StoreData(1 To 20) As String
Set cnn = New ADODB.Connection
Set cmd = New ADODB.Command
Set res = New ADODB.Recordset
sql = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\Testdata.mdb;Persist Security Info=False"
cnn.Open sql
For i = 1 To 20
StoreData(i) = i * i
Next
For i = 1 To 20
storestr = storestr & "','" & StoreData(i)
Next
str = "insert into data values('" & Date & "','" & Time() & storestr & "')"
cmd.ActiveConnection = cnn
cmd.CommandText = str
cmd.CommandType = adCmdText
cmd.Execute
cnn.Close
End Sub
补充:VB , 控件