Microsoft KB Archive/273821

= How To Programmatically Set Parameter Values for a Command Object in the DataEnvironment =

Article ID: 273821

Article Last Modified on 7/1/2004

-

APPLIES TO


 * Microsoft Visual Basic 6.0 Professional Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition

-



This article was previously published under Q273821



SUMMARY
This article describes how to programmatically set or change parameter values for a Command Object in the DataEnvironment.



MORE INFORMATION
 Create a new Visual Basic Standard EXE project. Form1 is created by default. From the Project menu, choose Add Data Environment. DataEnvironment1 and Connection1 are created by default. Right-click Connection1, choose Properties, select Microsoft OLE DB Provider for SQL Server, and then click Next. Select your SQL Server Name. Select the Use a specific User name and password: option to log on to your server. Provide the proper User Name and Password information for your chosen server, and check Allow Saving Password. Select the Northwind database on your SQL Server, click Test Connection, and then click OK. Right-click Connection1 and choose Add Command. Command1 is created by default. Right-click on Command1 and choose Properties. Choose Connection1 as the Connection for Command1. Choose the SQL Statement option as the Source of Data. Enter the following SQL statement in the text box that appears: Select EmployeeID, LastName, Country from Employees where Country=?

</li> On the Parameters tab, Param1 is created by default. Select Input as the Direction, adVarChar as the DataType for the Input Parameter, click Apply, and then click OK.</li> Close the DataEnvironment window.</li> Draw a Text Box and a Command Button on Form1, and set the Text Property of the Text Box to blank.</li> On the Toolbox, right-click and select Components. Select the Microsoft DataGrid (OLEDB) control from the list of available controls, click Apply, and then click Close.</li> Draw a DataGrid control to Form1. DataGrid1 is created by default. NOTE: Do not set the DataSource and DataMember properties for DataGrid1. Leave these blank.</li>  Copy the following code into the click event of Command1: Dim mystr As String mystr = Text1.Text

DataEnvironment1.Command1 mystr

Set DataGrid1.DataSource = DataEnvironment1.rsCommand1 DataGrid1.Refresh </li> Run the project. Enter USA in the Text Box, click the Command Button, and note that the grid is populated with Employees who are located in the USA.</li></ol>

Keywords: kbhowto KB273821

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.