HOWTO: Create an HTML Page Using ADO and MSFlexGrid
ID: Q186287
|
The information in this article applies to:
-
Microsoft Visual Basic Enterprise Edition for Windows, version 6.0
-
ActiveX Data Objects (ADO), versions 1.0, 1.5, 2.0, 2.1 SP2
SUMMARY
This article describes how to create a Web page that combines the
MSFlexGrid control with ActiveX Data Objects (ADO).
MORE INFORMATION
Below is an HTML example that uses the MSFlexGrid control with ActiveX Data
Objects (ADO) to produce a Web page from a database stored on the client
machine. The project shows the use of the GetString function, which is new
to Visual Basic 6.0.
NOTE: This code work correctly only on machines with Visual Basic 6.0
installed; it does not work on a machine with Visual Basic 5.0 installed.
Although this example uses a local reference to the database, the reference
could point to a remote database's directory, and the server's name can be
changed to reflect a remote machine name.
Step-by-Step Procedure
- Start an instance of Notepad.
- Cut and paste the code below into the instance of Notepad
- Edit the connection string to match your machine.
- Save the file as MyADOpage.html.
- Double-click the newly saved file to invoke IE and the Web page.
You can also use the ActiveX control pad to add additional ActiveX controls
to the project for additional functionality:
<HTML>
<HEAD>
<TITLE>New Page</TITLE>
</HEAD>
<BODY>
<OBJECT ID="MSFlexGrid1" WIDTH=787 HEIGHT=159
CLASSID="CLSID:6262D3A0-531B-11CF-91F6-C2863C385E30">
<PARAM NAME="_ExtentX" VALUE="20796">
<PARAM NAME="_ExtentY" VALUE="4207">
<PARAM NAME="_Version" VALUE="393216">
<PARAM NAME="AllowUserResizing" VALUE="1">
</OBJECT>
<SCRIPT LANGUAGE = "VBSCRIPT">
Sub Window_OnLoad()
Dim MyCon
Dim ADC
Set MyCon = CreateObject("ADODB.Connection")
Set ADC = CREATEOBJECT("ADODB.RECORDSET")
MyCon.Open "Driver={Microsoft Access Driver (*.mdb)};Server=Machine
Name;dbq=C:\Program Files\Microsoft Visual Studio\vb98\NWind.mdb"
ADC.Open "SELECT * FROM PRODUCTS", MyCon, , , adOpenKeyset
MSFlexGrid1.Cols = ADC.Fields.Count + 1
Dim V
Do While Not ADC.EOF
V = V + 1
ADC.MoveNext
Loop
ADC.MoveFirst
MSFlexGrid1.Rows = V + 1
MSFlexGrid1.Row = 0
MSFlexGrid1.Col = 1
ADC.MoveFirst
Dim MyResource
MyResource = ADC.GetString
MsFlexGrid1.Cols = ADC.Fields.Count
For X = 0 To ADC.Fields.Count - 1
MSFlexGrid1.TextMatrix(0, X) = ADC.Fields(X).Name
Next
MSFLEXGRID1.Row = 1
MSFLEXGRID1.Col = 0
MSFLEXGRID1.RowSel = MSFLEXGRID1.Rows - 1
MSFLEXGRID1.ColSel = MSFLEXGRID1.Cols - 1
MSFLEXGRID1.Clip = MyResource
MSFLEXGRID1.RowSel = MSFLEXGRID1.Row
MSFLEXGRID1.ColSel = MSFLEXGRID1.Col
End Sub
</SCRIPT>
</BODY>
</HTML>
REFERENCES
For more information about ADO, use the Visual Basic Help.
Query on ADO, DHTML, and/or MSFlexGrid.
(c) Microsoft Corporation 1998, All Rights Reserved. Contributions by
Richard T. Edwards, Microsoft Corporation
Additional query words:
Keywords : kbADO kbCtrl kbDatabase kbVBp600 kbGrpVBDB kbGrpMDAC kbDSupport kbADO210sp2 kbMDAC210SP2
Version : WINDOWS:1.0,1.5,2.0,2.1 SP2,6.0
Platform : WINDOWS
Issue type : kbhowto