如下,定义的rsPsHA有.UpdateBatch和MoveLast和MovePrevious.....,我现在要查询一个表里的某一个数据该如何做阿,比如有两列,type_id和type_name,我要查询typeid=111对应的type_name,该如何做,忘高手赐教!
Private rsPsHA As ADODB.Recordset
With rsPsHA
Select Case Index
Case 0
.UpdateBatch
.MoveLast
Case 1
.CancelUpdate
If .RecordCount <> 0 Then
.MoveFirst
End If
End Select
End With
Private rsPsHA As ADODB.Recordset
With rsPsHA
Select Case Index
Case 0
.UpdateBatch
.MoveLast
Case 1
.CancelUpdate
If .RecordCount <> 0 Then
.MoveFirst
End If
End Select
End With
rspsha.open "select type_name from tablename where type_id='111'",conn,adopenkeyset,adlockreadonly
if rspsha.reocrdcount>0 then
msgbox rspsha!type_name &""
else
msgbox "没有记录!",48,"提示"
end if
rspsha.close
set rspsha=nothing
Public mCnnString As String '定义连接字符串变量Private Sub Form_Load()
mCnnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\db1.mdb" & ";Persist Security Info=False" '给连接字符串赋值
End SubPrivate Sub Command1_Click() '查找
Dim rsPsHA As New ADODB.Recordset
Dim cnPsHA As New ADODB.Connection
cnPsHA.Open mCnnString
cnPsHA.CursorLocation = adUseClient
rsPsHA.Open "Select type_name From Table1 Where type_id = '" & "111'", mCnnString, adOpenStatic, adLockOptimistic, adCmdText
If Not (rsPsHA.Bof And rsPsHA.Eof) Then
MsgBox rsPsHA("type_name")
Else
MsgBox "无该记录!"
End If
rsPsHA.Close
cnPsHA.Close
Set rsPsHA = Nothing
Set cnPsHA = Nothing
End Sub
Dim mTemp As String
rsPsHA.Open "Select type_name From Table1 Where type_id = '" & mTemp & "'", mCnnString, adOpenStatic, adLockOptimistic, adCmdText
字段 type_id 为数值型时:SQLSTR="select ..... where type_id =" & xxx & "...."
字段 type_id 为文本类时:SQLSTR="select ..... where type_id ='" & xxx & "'...."试一下,有问题再牛皮
可以