Microsoft KB Archive/186287

= How To Create an HTML Page Using ADO and MSFlexGrid =

Article ID: 186287

Article Last Modified on 3/2/2005

-

APPLIES TO


 * Microsoft Visual Basic 6.0 Enterprise Edition
 * Microsoft ActiveX Data Objects 1.0
 * Microsoft ActiveX Data Objects 1.5
 * Microsoft ActiveX Data Objects 2.0
 * Microsoft ActiveX Data Objects 2.1 Service Pack 2
 * Microsoft ActiveX Data Objects 2.5
 * Microsoft ActiveX Data Objects 2.6
 * Microsoft ActiveX Data Objects 2.7

-



This article was previously published under Q186287



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 only 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

 * 1) Start an instance of Notepad.
 * 2) Cut and paste the code below into the instance of Notepad
 * 3) Edit the connection string to match your machine.
 * 4) Save the file as MyADOpage.html.
 * 5) 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:   New Page        



Sub Window_OnLoad Dim MyCon Dim ADC Set MyCon = CreateObject("ADODB.Connection") MyCon.Open "dsn=AdvWorks" Set ADC = CREATEOBJECT("ADODB.RECORDSET")

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>

<div class="references_section">