掲示板システム
ホーム
アクセス解析
カテゴリ
ログアウト
一つのテーブルから複数の条件でレコードセットを取得するには? (ID:113445)
名前
ホームページ(ブログ、Twitterなど)のURL (省略可)
本文
50才ならまだこの発想はできるはず…1個1個付ければ良いんです。 頭を柔らかくしましょう。まず初心者は効率より1手順ずつ自分の力量で できる範囲で実現させることです。(まぁ、効率はずっと意識しておくべき 項目ではありますが…) [VB6.0] '--------------------------------------------------------------- Private Sub cmd1_Click() Dim rs As ADODB.Recordset Dim tt As String Dim tn As String Dim ta As String Dim criteria As String Dim strsql As String Dim Key(3) As String Dim crlen As Integer Dim i As Integer Dim rc As Integer tt = Text1.Text tn = Text2.Text ta = Text3.Text If tt = "" Then Key(1) = "" Else ' Key(1) = "電話番号=" & tt Key(1) = "電話番号='" & tt & "'" End If If tn = "" Then Key(2) = "" Else ' Key(2) = "氏名=" & tn Key(2) = "氏名='" & tn & "'" End If If ta = "" Then Key(3) = "" Else ' Key(3) = "住所 =" & ta Key(3) = "住所 ='" & ta & "'" End If criteria = "" For i = 1 To 3 If Key(i) = "" Then ' Else criteria = criteria & Key(i) & " and " End If Next i If criteria = "" Then Exit Sub End If crlen = Len(criteria) criteria = Left(criteria, crlen - 5) '最終の" and "を取り除く ' strsql = "select * from 個人情報 where '" & criteria & "'" strsql = "select * from 個人情報 where " & criteria Set rs = New ADODB.Recordset rs.ActiveConnection = cn rs.Source = strsql rs.CursorType = adOpenStatic rs.LockType = adLockReadOnly rs.Properties("irowsetidentity") = True rs.Open Set dg1.DataSource = rs rc = rs.RecordCount End Sub
←解決時は質問者本人がここをチェックしてください。
戻る
掲示板システム
Copyright 2020 Takeshi Okamoto All Rights Reserved.