问题描述
- 程序编译错误,recordcount返回值为-1
-
Option ExplicitPrivate Sub text1_validate(cancel As Boolean)
If IsNumeric(Text1.Text) = False Then
MsgBox "请输入日期"
End If
End SubPrivate Sub Command1_Click()
Dim cn As New ADODB.Connection
Dim cm As New ADODB.Command
Dim rs As New ADODB.Recordset
Dim cn1 As New ADODB.Connection
Dim rs1 As New ADODB.Recordset
Dim cm1 As New ADODB.Command
Dim sinput As String
Dim ID As String
Dim IDNUMBER As String
Dim NAME As String
Dim SEX As String
Dim BIRTHDAY As String
Dim SZTID As String
Dim BANKID As String
Dim SBID As String
Dim NID As String
Dim SBTYPE As String
Dim PRITEDATE As String
Dim FLAGID As String
Dim MEM As String
Dim a As String
Dim b As String
Dim no As String
Dim str As String
cn.Open "provider=microsoft.jet.oledb.4.0;data source=" & App.Path & "LOG.mdb"
rs.ActiveConnection = cn
'cn.ConnectionString = "dsn=DataCard"
cn1.Open "provider=microsoft.jet.oledb.4.0;data source=" & App.Path & "CardData.mdb"
rs1.ActiveConnection = cn1
cn.CursorLocation = adUseClient
sinput = Text1.Text
rs.Open "SELECT ID,IDNUMBER,NAME,SEX,BIRTHDAY,SZTID,BANKID,SBID,NID,SBTYPE,PRITEDATE,FLAGID,MEM FROM DataCard WHERE DataCard.MEM = 'sinput'", cn
If rs.RecordCount > 0 Then
rs.MoveLast
rs.MoveFirst
Do Until rs.EOF
' str = rs!ID + "" + rs!IDNUMBER + "" + rs!NAME + "" + rs!SEX + "" + rs!BIRTHDAY + "" + rs!SZTID + "" + rs!BANKID + "" + rs!SBID + "" + rs!NID + "" + rs!SBTYPE + "" + rs!PRITEDATE + "" + rs!FLAGID + "" + rs!MEM + ""
a = sinput
b = rs!MEN
If a = b Then
no = no + 1
Else
no = 1
cm1.CommandType = adCmdFile
cm1.CommandText = "insert into CardData values('" & ID & "','" & IDNUMBER & "','" & NAME & "','" & SEX & "','" & BIRTHDAY & "','" & SZTID & "','" & BANKID & "','" & SBID & "','" & NID & "','" & SBTYPE & "','" & PRITEDATE & "','" & FLAGID & "')"
cm1.Execute
rs.MoveNextEnd If Loop
End If
rs1.Close
cn1.Close
rs.Close
cn.Close
End Sub
解决方案
你在access用同样sql查询看看