Quantcast
Channel: VBForums - Visual Basic 6 and Earlier
Viewing all articles
Browse latest Browse all 21254

vb6 query problem

$
0
0
I have this query to get record

Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
Dim sSQL As String
sSQL = "SELECT * FROM customer where (custid = '' or custid = '" & Text1.Text & "') and (custfn = '' or custfn = '" & Text2.Text & "')"
rs.Open sSQL, cn, adOpenKeyset, adLockOptimistic

my problem is that when I do this query, text1 and text2 filter must have a value or else no result.

what I want to achieve is the user to be able to filter a result using only text1.text or text2.text and also both.

like for example if I have

1,dave
2,roman
3,nathan

if I filter using id=3 then the result should be nathan
if I filter using id=1 and custfn=nathan then there should be no result because the two record is conflicting
if I filter using custfn=roman, then it will return the id=2 and custfn=roman

how should I fix that query of mine to achieve the above result?

Viewing all articles
Browse latest Browse all 21254

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>