منتدى فيجوال بيسك لكل العرب | منتدى المبرمجين العرب
[vb6.0] البحث في أكثر من جدول - نسخة قابلة للطباعة

+- منتدى فيجوال بيسك لكل العرب | منتدى المبرمجين العرب (http://vb4arb.com/vb)
+-- قسم : قسم لغات البرمجة الاخرى (http://vb4arb.com/vb/forumdisplay.php?fid=4)
+--- قسم : قسم لغة vb6.0 (http://vb4arb.com/vb/forumdisplay.php?fid=18)
+---- قسم : قسم أسئلة vb6.0 (http://vb4arb.com/vb/forumdisplay.php?fid=28)
+---- الموضوع : [vb6.0] البحث في أكثر من جدول (/showthread.php?tid=18885)



البحث في أكثر من جدول - أيمن الفخراني - 20-01-17

السلام عليكم
لدي سؤال عن كيفية البحث عن كلمة ما في اكثر من جدول وعرض النتائج في لست فيو
انا استحدم هذا الكود لكن اجده بطئ  هل يوجد طريقة آخرى
كود :
     If MB.state = 1 Then MB.Close
   MB.Open "select * from table1 where nass like '%" & Text1.text & "%'", DB, adOpenStatic, adLockReadOnly
   If MB.RecordCount > 0 Then
       Do While Not MB.EOF
   
   Set lst = ListView1.ListItems.add(, , MB!nass)
lst.SubItems(1) = "كتاب 1"
       MB.MoveNext
       DoEvents
   Loop
   MB.Close
End If
     If MB.state = 1 Then MB.Close
   MB.Open "select * from table2 where nass like '%" & Text1.text & "%'", DB, adOpenStatic, adLockReadOnly
   If MB.RecordCount > 0 Then
       Do While Not MB.EOF
   
   Set lst = ListView1.ListItems.add(, , MB!nass)
lst.SubItems(1) = "كتاب 2"
       MB.MoveNext
       DoEvents
   Loop
   MB.Close
End If
     If MB.state = 1 Then MB.Close
   MB.Open "select * from table3 where nass like '%" & Text1.text & "%'", DB, adOpenStatic, adLockReadOnly
   If MB.RecordCount > 0 Then
       Do While Not MB.EOF
   
   Set lst = ListView1.ListItems.add(, , MB!nass)
lst.SubItems(1) = "كتاب 3"
       MB.MoveNext
       DoEvents
   Loop
   MB.Close
End If



RE: البحث في أكثر من جدول - أيمن الفخراني - 21-01-17

هل من الممكن اختصار الكود السابق؟؟


RE: البحث في أكثر من جدول - Ahmed_Mansoor - 22-01-17

وعليكم السلام ورحمة الله وبركاته

أهلا بك أخي الكريم , هذا تعديل لجملة الإستعلام ليختصر عليك الكود المكرر :

PHP كود :
If MB.state 1 Then MB.Close
MB
.Open "select nass,'كتاب1' as zTitle from table1 where nass like '%" Text1.Text "%'" _
        
" UNION " _
        
"select nass,'كتاب2' as zTitle from table2 where nass like '%" Text1.Text "%'" _
        
" UNION " _
        
"select nass,'كتاب3' as zTitle from table3 where nass like '%" Text1.Text "%'" _
        
" Order By zTitle,nass"DBadOpenStaticadLockReadOnly

If MB.RecordCount 0 Then
   
   MB
.MoveFirst
   
   
Do While Not MB.EOF
      Set lst 
ListView1.ListItems.Add(, , MB!nass)
      
lst.SubItems(1) = MB!zTitle
      MB
.MoveNext
      DoEvents
   Loop
   
End 
If

If 
MB.state 1 Then MB.Close 



RE: البحث في أكثر من جدول - أيمن الفخراني - 22-01-17

جزاكم الله خيرا أخي الكريم