2 freesias0101 freesias0101 于 2014.05.09 10:04 提问

程序编译错误,recordcount返回值为-1

Option Explicit

Private Sub text1_validate(cancel As Boolean)
If IsNumeric(Text1.Text) = False Then
MsgBox "请输入日期"
End If
End Sub

Private 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.MoveNext

     End If
  Loop

End If
rs1.Close
cn1.Close
rs.Close
cn.Close
End Sub

1个回答

feiyun0112
feiyun0112   Rxr 2014.05.09 18:02

你在access用同样sql查询看看

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!