Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to use SQL in Grid ?
Message
From
07/10/1998 04:05:12
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
06/10/1998 23:30:32
General information
Forum:
Visual FoxPro
Category:
Forms & Form designer
Miscellaneous
Thread ID:
00143788
Message ID:
00144476
Views:
25
>>>>Suppose you have 3 textboxes (you have one) as txt1, txt2, txt3 referring to fields fld1, fld2, fld3 in your SQL :
Grid.init
>>>>with this
>>>>  .recordsourcetype = 4 && SQL
>>>>  .recordsource = "select * from mytable "+;
>>>>     "where fld1 = trim(thisform.txt1.value) " +;
>>>>     "and fld2 = trim(thisform.txt2.value) " +;
>>>>     "and fld3 = trim(thisform.txt3.value) " +;
>>>>     "into cursor grdCursor"
>>>>endwith
>>>>
>>>>* Lostfocus of textboxes
>>>>thisform.mygrid.refresh
Cetin
>>>
>>>
>Thanks again for your suggestion. I have tired your code but nothing happen in my Grid. I don't know why ? When I run form, my grid was empty. And after I put condition in txt1.value, my grid also empty. Any more suggestion. Thanks
>From Nophua.
Now,
Are you sure you're referring to correct table in SQL (mytable is an Example) and are you sure you're using a compatible comparison in SQL (does SQL run correctly from command window when thisform.txt1.value is replaced with some "text") ie: if field type is date then it would be like where fld1 = thisform.txt1.value (no trim). Here is a sample demonstrating indeed it does work :
oForm = createobject("myForm")
oForm.show
READ events

DEFINE CLASS myform AS form
  DoCreate = .T.
  Caption = "Test Form"
  Name = "myform"
  ControlBox = .F.
  Top = 0
  Left = 0
  Height = 282
  Width = 630

  ADD OBJECT text1 AS textbox WITH ;
    Height = 23, ;
    Left = 7, ;
    Top = 4, ;
    Width = 100, ;
    Name = "Text1"

  ADD OBJECT text2 AS textbox WITH ;
    Height = 23, ;
    Left = 109, ;
    Top = 4, ;
    Width = 100, ;
    Name = "Text2"

  ADD OBJECT grid1 AS grid WITH ;
    Height = 200, ;
    Left = 5, ;
    Top = 32, ;
    Width = 609, ;
    Name = "Grid1"

  ADD OBJECT mycommandbutton1 AS commandbutton WITH ;
    Top = 242, ;
    Left = 522, ;
    Autosize = .t., ;
    Cancel = .T., ;
    Caption = "Close", ;
    Name = "Commandbutton1"

  PROCEDURE commandbutton1.Click
    thisform.release
    Clear events
  ENDPROC

  PROCEDURE grid1.Init
    this.recordsourcetype = 4
    this.recordsource = ;
      [select * from home()+"samples\data\customer" ]+;
      [where contact = trim(ThisForm.Text1.value)]+;
      [into cursor grdCursor]
  ENDPROC

  PROCEDURE text1.LostFocus
    thisform.grid1.refresh
  ENDPROC

ENDDEFINE
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Reply
Map
View

Click here to load this message in the networking platform