vb存入数据库数据问题
目的很简单:就是将串口传来的数据存入数据库。可是写了一段程序显示:实时错误91 对象变量或with块变量未设置。请高手指点Private Sub MSComm1_OnComm()
Select Case MSComm1.CommEvent
Case comEvReceive ' 收到 RThreshold # of
Dim hk As Variant
'Dim conn As New adodb.Connection
xv: hk = MSComm1.Input
If Check2.Value = 1 Then
Text1.Text = Text1.Text & Hex(hk(0)) & " "
Else
Text1.Text = Text1.Text & hk
Adodc1.Recordset.AddNew
Adodc1.Recordset.Fields("数据") = Text1.Text
End If
If MSComm1.InBufferCount <> 0 Then
GoTo xv
End If
End Select
End Sub --------------------编程问答-------------------- Adodc1是否有在窗口上放入控件,是否有设置了数据库相关参数? --------------------编程问答-------------------- adodc1控件没有与数据库建立连接吧 --------------------编程问答-------------------- http://download.csdn.net/detail/veron_04/3827200 --------------------编程问答--------------------
'┏〓〓〓〓〓〓〓〓〓 GetRsFromMdb,start 〓〓〓〓〓〓〓〓〓┓
'[简介]:
'读取ACCESS mdb格式文件中指定表格数据
Function GetRsFromMdb(MdbFile As String, Table, Optional Where As String, Optional Pass As String, Optional ErrInfo As String, Optional User As String) As ADODB.Recordset
'[mycode_id:44],edittime:2012/4/13 8:14:13
On Error GoTo Err
ErrInfo = ""
Dim conn As ADODB.Connection
Dim Sql As String
Set conn = CreateObject("adodb.connection")
conn.Open "dbq=" + MdbFile + ";defaultdir=;driver={microsoft access driver (*.mdb)};", User, Pass
Set GetRsFromMdb = CreateObject("adodb.recordset")
Sql = "select * from [" & Table & "] " & Where
GetRsFromMdb.Open Sql, conn, 1, 3
Exit Function
Err:
DebugErr "GetRsFromAccdb"
ErrInfo = "错误号:" & Err.Number & vbCrLf & "错误信息:" & Err.Description
End Function
'┗〓〓〓〓〓〓〓〓〓 GetRsFromMdb,end 〓〓〓〓〓〓〓〓〓┛
DIM rS AS ADODB.RECORDSET
SET RS=GetRsFromMdb("C:\1.MDB","表1")
RS.ADDNEW
RS("字段1")="33"
RS.UPDATE
RS.CLOSE
补充:VB , VBA