0% found this document useful (0 votes)
42 views12 pages

Smiley 018

The document describes how to use the ADO Data Environment Designer in Visual Basic 6 to create an ADO connection and command object to retrieve and display data. It explains how to add a data environment, set the connection properties, create a command object with an SQL statement, and bind controls like a datagrid or textboxes to display the recordset. Dragging a command object onto a form will automatically generate labels and textboxes for each field to display the data with less code than using a data control.

Uploaded by

satheesh8487
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views12 pages

Smiley 018

The document describes how to use the ADO Data Environment Designer in Visual Basic 6 to create an ADO connection and command object to retrieve and display data. It explains how to add a data environment, set the connection properties, create a command object with an SQL statement, and bind controls like a datagrid or textboxes to display the recordset. Dragging a command object onto a form will automatically generate labels and textboxes for each field to display the data with less code than using a data control.

Uploaded by

satheesh8487
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Use the ADO Data Environment Designer to create an ADO Connection in Visual Basic 6

Use the ADO Data Environment Designer to create an ADO Connection in Visual Basic 6
When we use the ADO Data Environment Designer to make our connection, we don't need a Data Control, so let's pretend that we've created a new project, placed the DataGrid in our toolbox, and placed it on our form. Now we need to find and startup the Data Environment Designer. To do that, select Project-Add Data Designer from the Visual Basic Menu Bar

If you don't see Add Data Environment as an option, select Project-Components from the Visual Basic Menu Bar, click on the Designers Tab, and locate and select the Data Environment there

http://www.johnsmiley.com/cis18.notfree/Smiley018/Smiley018.htm (1 of 12)3/28/2004 11:57:32 AM

Use the ADO Data Environment Designer to create an ADO Connection in Visual Basic 6

Once you select Add Data Environment from the Project menu, you should see this window

http://www.johnsmiley.com/cis18.notfree/Smiley018/Smiley018.htm (2 of 12)3/28/2004 11:57:32 AM

Use the ADO Data Environment Designer to create an ADO Connection in Visual Basic 6

Right-click on the Connection object in the Data Environment Window and select Properties

This window will appear

http://www.johnsmiley.com/cis18.notfree/Smiley018/Smiley018.htm (3 of 12)3/28/2004 11:57:32 AM

Use the ADO Data Environment Designer to create an ADO Connection in Visual Basic 6

Look familiar? It should, it's the same wizard we saw when we created the connection using the Data Control. I'll repeat those same steps here (but in the interest of space I won't show you). Now we have a connection, but no recordset. Using the Data Environment, we must create a recordset via a Command Object. To create the Command Object, right-click on the Connection Object and select Add Command from the menu

http://www.johnsmiley.com/cis18.notfree/Smiley018/Smiley018.htm (4 of 12)3/28/2004 11:57:32 AM

Use the ADO Data Environment Designer to create an ADO Connection in Visual Basic 6

A Command object will appear in the Data Environment

Right-click on it, and select Properties. This window will appear

http://www.johnsmiley.com/cis18.notfree/Smiley018/Smiley018.htm (5 of 12)3/28/2004 11:57:32 AM

Use the ADO Data Environment Designer to create an ADO Connection in Visual Basic 6

We'll use a SQL Statement to create the underlying recordset (if you are not familiar with SQL, click on the SQL Builder button)

http://www.johnsmiley.com/cis18.notfree/Smiley018/Smiley018.htm (6 of 12)3/28/2004 11:57:32 AM

Use the ADO Data Environment Designer to create an ADO Connection in Visual Basic 6

and after clicking on the Apply Button, we now have a properly defined Data Environment

At this point, to 'bind' our DataGrid to the Data Environment Object that we've
http://www.johnsmiley.com/cis18.notfree/Smiley018/Smiley018.htm (7 of 12)3/28/2004 11:57:32 AM

Use the ADO Data Environment Designer to create an ADO Connection in Visual Basic 6

just created, all we need to do open up the Properties Window for the Data Grid and specify the DataEnvironment as our Data Source and the Command Object in the DataMember property of the Data Grid

Now if we run the program, well find that the DataGrid is now bound to our DataEnvironment

http://www.johnsmiley.com/cis18.notfree/Smiley018/Smiley018.htm (8 of 12)3/28/2004 11:57:32 AM

Use the ADO Data Environment Designer to create an ADO Connection in Visual Basic 6

At this point, you may be thinking that the DataEnvironment really hasnt bought you all that muchafter all, we can achieve the same functionality with the Data Control. Thats true, but heres something the Data Control can never do for us. Suppose, instead of using a Data Grid to display the records in our Recordset, wed like to display them in Textboxes? Its pretty easy to display data in Textboxes using a Data Controlyou just place labels and Textboxes on a form, and individually set the DataSource and DataField Properties of each Textbox to point to the Data Control. The DataEnvironment makes that even easier. For now, lets delete the Data Grid from this form, and then click and drag the Command Object from the DataEnvironment Designer to our form---watch what happens!

http://www.johnsmiley.com/cis18.notfree/Smiley018/Smiley018.htm (9 of 12)3/28/2004 11:57:32 AM

Use the ADO Data Environment Designer to create an ADO Connection in Visual Basic 6

As you can see, Visual Basic automatically creates Label and Textbox controls for each field in the Recordset that is produced by the Command Object. This can be a tremendous time saver, especially if the Recordset contains a lot of fields. Lets take some time to make the form a bit tidier

http://www.johnsmiley.com/cis18.notfree/Smiley018/Smiley018.htm (10 of 12)3/28/2004 11:57:32 AM

Use the ADO Data Environment Designer to create an ADO Connection in Visual Basic 6

and then run the program. Voila, Data!

Not bad for the little work we had to do to get thisbut theres a big problem theres no way to move from record to record, as we have when we use a Data Control. Lets place a command button on the form, and place this code in its Click Event Procedurethis will enable us to move to the next record in the Recordset Private Sub Command1_Click() DataEnvironment1.rsCommand1.MoveNext End Sub Now if we run the program, and click on the Command Button, well easily be able to move to the next record in the Recordset

http://www.johnsmiley.com/cis18.notfree/Smiley018/Smiley018.htm (11 of 12)3/28/2004 11:57:32 AM

Use the ADO Data Environment Designer to create an ADO Connection in Visual Basic 6

Summary
I hope you enjoyed this article on using the Data Environment.

http://www.johnsmiley.com/cis18.notfree/Smiley018/Smiley018.htm (12 of 12)3/28/2004 11:57:32 AM

You might also like