Local Cnx As ADODB.Connection Local Rds As ADODB.Recordset SET STEP ON Cnx=Createobject("adodb.connection") Rds=Createobject("adodb.recordset") Cnx.CursorLocation= 3 && adUseClien Try Cnx.Open ("DSN=prueba;UID=consulta;PWD=consulta") Catch To oErr ? "Catch:",oErr.errorno Finally Endtry && Could open the connection and execute the query Rds.Open(Rtrim(Thisform.text2.Value),Cnx,1,1) _Screen.AddProperty("oBrow1") If Rds.RecordCount > 0 Set Procedure To ADOBrowse.prg _Screen.oBrow1= Createobject("ADOBrowse", Rds, "Predios") Else Wait Window "There was no records..." Timeout 3 EndifAnd last... a prg named ADOBrowse.prg (If you see the code above), with this content:
*-- ADOBrowse.Prg on-the-fly browse ADO recordset - 08/24/00 *-- Parameters: myRS = ADO RS object, myCaption = Form's caption *-- who wants to ? myRS.Fields("you-name-it").Value over and over??? *-- Author: J.Crescencio Flores, MCSD *-- For those XBase - die hards!! *!* Requires MSDataGrid ActiveX control to work *!* *-- 12/09/00 Workaround Datagrid problem with non-bookmarkable RS's *------------------------------------------------------------------* Define Class ADOBrowse As Form oRS = .F. cFile = "nofile" Name = "frmRS" Height = 300 Width = 500 Autocenter = .T. Add Object "Grid1" As MSGridControl With ; Height = Thisform.Height - 10,; Width = Thisform.Width - 5,; Visible = .T. Proc Init Parameters myRS, myCaption Local oHack If Parameters()=0 Or Vartype(myRS)#"O" Then MessageBox("Required Parameter Missing", 16, "Error: No Data!") Return .F. Endif If PCount()>1 Then myCaption = Transform(myCaption) This.Caption = myCaption Endif *-- If recordset does not support bookmarks, save original to disk *-- and create another recordset object with the right properties *-- Datagrid control barfs if provider does not support them. If Not myRS.Supports(8192) Then && adBookMark This.cFile = Substr(Sys(2015), 3) myRS.Save(This.cFile) oHack = CreateObject("ADODB.Recordset") oHack.Cursorlocation = 3 && adUseClient oHack.Open(This.cFile) && type is adOpenStatic This.oRS = oHack Else This.oRS = myRS Endif With This .Grid1.Object.AllowAddNew = .F. .Grid1.Object.AllowDelete = .F. .Grid1.Object.AllowUpdate = .F. .Grid1.Object.DataSource = .oRS .ResizeCols() .Visible = .t. EndWith EndProc *-- Resize grid columns based on field's size or *-- name length, whichever is greater Proc ResizeCols() Local loClmn, lnName, lnSize For Each loClmn In This.Grid1.Object.Columns lnSize = This.oRS.Fields(loClmn.ColIndex).definedsize lnName = Len(This.oRS.Fields(loClmn.ColIndex).Name) loClmn.Width = This.TextWidth("A") * Iif(lnSize>lnName, lnSize, lnName) If This.oRS.Fields(loClmn.ColIndex).Type = 11 Then &&adBoolean With loClmn.DataFormat .Type = 5 .truevalue = "Yes" .falsevalue = "No" EndWith EndIf Next EndProc *-- Resize ole container with form Proc Resize If This.Height>=100 And This.Width>=100 Then This.Grid1.Height = This.Height - 10 This.Grid1.Width = This.Width - 5 EndIf EndProc *-- Close recordset if opened from file, delete file Proc Destroy If This.oRS.Source = This.cFile Then This.oRS.Close This.oRS = .Null. Erase (This.cFile) Endif EndProc EndDefine Define Class MSGridControl as OLEControl OLEClass = "MSDataGridLib.DataGrid.1" EndDefineHope work for you...