Dim conn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim Str1 As String
Dim Str2 As String
Dim Str3 As String
Dim strSQL As String
Dim 合格判断 As Long
Dim 采集日期 As Date
Dim 采集时间 As String
Str1 = "Provider=Microsoft.Jet.OLEDB.4.0;"
Str2 = "Data Source=E:\temp1.mdb;"
Str3 = "Jet OLEDB:Database Password="
conn.Open Str1 & Str2 & Str3
strSQL = " tb "
rs.Open strSQL, conn, 3, 3
rs.AddNew
rs!合格判断 = Text2.Text
rs!采集日期 = Text3.Text
rs!采集时间 = Text4.Text
rs.Update
rs.Close
conn.Close
Adodc1.Refresh
End Select
End Sub各位这是我写的调用数据库的程序在这一句rs!合格判断 = Text2.Text提示类型不匹配
请各位大侠 帮忙看看怎么修改

解决方案 »

  1.   

    Dim conn As New ADODB.Connection
    Dim rs As New ADODB.Recordset
    Dim Str1 As String
    Dim Str2 As String
    Dim Str3 As String
    Dim strSQL As String
    'Dim 合格判断 As Long
    'Dim 采集日期 As Date
    'Dim 采集时间 As String
    Str1 = "Provider=Microsoft.Jet.OLEDB.4.0;"
    Str2 = "Data Source=E:\temp1.mdb;"
    Str3 = "Jet OLEDB:Database Password="
    conn.Open Str1 & Str2 & Str3if trim(text2.text)="" then
        msgbox "请输入合格判断!",48,"提示"
        exit sub
    else
        if not isnumeric(text2.text) then
            msgbox "请输入数值型数据!",48,"提示"
            text2.setfocus
            exit sub
        end if
    end ifif trim(text3.text)="" then
        msgbox "请输入采集日期!",48,"提示"
        exit sub
    else
        if not isdate(text3.text) then
            msgbox "请输入日期型数据!",48,"提示"
            text3.setfocus
        end if
    end ifconn.execute "insert into tb(合格判断,采集日期,采集时间) values("& text2.text &",#"& text3.text &"#,'"& text4.text &"')"
    conn.Close
      

  2.   

    左手 同学   我的程序中的“合格判断” “采集日期” “采集时间”这三个数值是从串口捕捉到的信息
    我想通过ADO控件写到 我已经做好的ACCESS表格中  这样怎么弄哈?
    Private Sub MSComm1_OnComm()
    Select Case MSComm1.CommEvent
     Case comEvReceive '接收到数据Dim BytReceived()  As Byte
    Dim strBuff As Variant
    Dim strData As String
    Dim i As Integer
     
     
    strBuff = MSComm1.Input  '读入到缓冲区
     If MSComm1.InputMode = comInputModeBinary Then
     BytReceived() = strBuff  '如果是二进制接收模式则进行数据处理,否则直接显示字符串
      For i = 0 To UBound(BytReceived)
        If Len(Hex(BytReceived(i))) = 1 Then
        strData = strData & "0" & Hex(BytReceived(i)) & " " '如果只有一个字符,则前补0,如F显示0F,最后补空格
      Else         '方便显示观察如: 00 0F FE
        strData = vbCrLf & strData & Hex(BytReceived(i)) & "^"
                                         
      End If
                Next
                Text2 = Text2 & strData
                strData = ""
            Else
                Text2 = Text2 & strBuff
           
    End If
    Dim conn As New ADODB.Connection
    Dim rs As New ADODB.Recordset
    Dim Str1 As String
    Dim Str2 As String
    Dim Str3 As String
    Dim strSQL As String
    Dim 合格判断 As Long
    Dim 采集日期 As Date
    Dim 采集时间 As String
    Str1 = "Provider=Microsoft.Jet.OLEDB.4.0;"
    Str2 = "Data Source=E:\temp1.mdb;"
    Str3 = "Jet OLEDB:Database Password="
    conn.Open Str1 & Str2 & Str3
    strSQL = " tb "
    rs.Open strSQL, conn, 3, 3
    rs.AddNew
    rs!合格判断 = Text2.Text
    rs!采集日期 = Text3.Text
    rs!采集时间 = Text4.Text
    rs.Update
    rs.Close
    conn.Close
    Adodc1.Refresh
    End Select
    End Sub
      

  3.   

    字段类型 合格判断 为 数字 常整型
             采集日期       日期/时间
             采集时间       日期/时间
    Dim 合格判断 As Long
    Dim 采集日期 As Date
    Dim 采集时间 As String
    这是我在程序里的设置
      

  4.   

    看出错时 text2的值可以加val
      

  5.   

    串口的值怎么分到 text2、text3、text4 的?
      

  6.   

    ********88^01 02 03 00 01 22^33^44^55^66^77^88^
    ********88^01 02 03 00 02 22^33^44^55^66^77^88^
    把这些数据都存放在 text2里面 ,这些数据里开头的88是扩展帧的帧信息 01 02 03 00是标识符
     01 22^33^44^55^66^77^88^ 是接收到的数据8个字节 这里面就是计数没有其它信息
    text3存放系统日期
    text4存放系统时间
      

  7.   

    ********88^01 02 03 00 01 22^33^44^55^66^77^88^
    ********88^01 02 03 00 02 22^33^44^55^66^77^88^
    把这些数据都存放在 text2里面 ,这些数据里开头的88是扩展帧的帧信息 01 02 03 00是标识符
     01 22^33^44^55^66^77^88^ 是接收到的数据8个字节 这里面就是计数没有其它信息
    这些数据都是16进制的数据 因为我的传输总线要求必须用16进制的数据
      

  8.   

    rs!合格判断 = Text2.Text提示类型不匹配
    注意以下几点:
    “合格判断” 类型为long,则最好转换Text2.Text
    需要判断Text2.Text不为空的情况。判断Text2.Text不为空,且需要转换成功!
    rs!合格判断 = CLNG(Text2.Text)
      

  9.   

    按照你提示的方法修改程序后 仍然提示类型不匹配,而且Text2.Text为空  这是怎么回事?