MySQL データベースに対してレコードセットを作成し、開いてから切断しています。これは 1 つのクエリでは正しく機能しますが、データベースに行が存在する別のクエリでは 0 レコードが返されます。機能する場合は、レコードセットからもレコードを削除できます。
レコードを返すクエリ:
sql = "select convert(v.wonotes using UTF8) as WonData, v.wo_cat_id, v.id As wo_desc_id, v.line_no as line_no, " & _
" v.wo_id as wo_id, v.prop_id as prop_id, convert(v.description using UTF8) as description, v.cat_id as cat_id, " & _
" v.completion_date as completion_date from vw_property_wo_desc v " & _
" where v.wo_cat_id= 6 and **(v.wo_status = 'completed' or v.wo_status = 'approved')** " & _
" and v.wonotes is not null and v.wonotes<> '' "
レコードを返さないクエリ:
sql = "select convert(v.wonotes using UTF8) as WonData, v.wo_cat_id, v.id As wo_desc_id, v.line_no as line_no, " & _
" v.wo_id as wo_id, v.prop_id as prop_id, convert(v.description using UTF8) as description, v.cat_id as cat_id, " & _
" v.completion_date as completion_date from vw_property_wo_desc v " & _
" where v.wo_cat_id= 6 and **v.wo_status = 'unassigned'** " & _
" and v.wonotes is not null and v.wonotes<> '' "
他に変更はありません。
カーソルの種類を adOpenDynamic に変更すると、クエリはレコードを返しますが、接続を切断できません。これは、データベースにそのクエリを満たすレコードがあることを証明するためのものです。
切断されたレコードセットのコード:
With rsToUse
If .State = adStateOpen Then .Close
.ActiveConnection = GetConnection
.Source = sql
.CursorLocation = adUseClient
.CursorType = adOpenForwardOnly
.LockType = adLockBatchOptimistic
.Open
If .EOF Then
.Close
Exit Function
End If
.ActiveConnection = Nothing
End With
アイデアが尽きました、助けてください。