Microsoft KB Archive/304959

= How To Use Visual Studio .NET Server Explorer to Access Data =

Article ID: 304959

Article Last Modified on 5/23/2005

-

APPLIES TO


 * Microsoft Visual Studio .NET 2003 Enterprise Architect
 * Microsoft Visual Studio .NET 2003 Enterprise Developer
 * Microsoft Visual Studio .NET 2003 Academic Edition
 * Microsoft Visual Studio .NET 2002 Professional Edition
 * Microsoft Visual Studio .NET 2002 Enterprise Architect
 * Microsoft Visual Studio .NET 2002 Enterprise Developer
 * Microsoft Visual Studio .NET 2002 Academic Edition

-



This article was previously published under Q304959



IN THIS TASK
SUMMARY
 * Requirements
 * Use Server Explorer to Access and to Change Data
 * Display Data in a Windows Form

REFERENCES



SUMMARY
This step-by-step article describes how to use Visual Studio .NET Server Explorer to connect to and to change data in a Microsoft SQL Server database. This article also describes how to display this data in a data-bound Windows Form. You can also use Server Explorer to connect to and to change other databases by using the OleDb managed provider.

With Server Explorer, you can access data in Visual Studio .NET. You can use Server Explorer to connect to and to log on to database servers in your network, as well as to change data that is stored on those servers. You can also drag nodes from Server Explorer and drop them onto Visual Studio .NET designers to create preconfigured data components for use in your applications.

back to the top

Requirements
The following list outlines the recommended hardware, software, network infrastructure, and service packs that are required:
 * Microsoft Windows XP Professional, Microsoft Windows 2000 Professional, Microsoft Windows 2000 Server, Microsoft Windows 2000 Advanced Server, or Microsoft Windows NT 4.0 Server
 * Microsoft Visual Studio .NET
 * Microsoft SQL Server 7.0 or later

This article assumes that you are familiar with the following topic:
 * Visual Studio .NET

back to the top

Use Server Explorer to Access and to Change Data
 Follow these steps to create a new Visual Basic Windows Application project:  Start Visual Studio .NET. On the File menu, point to New, and then click Project. In the New Project dialog box, click Visual Basic Projects under Project Types, click Windows Application under Templates, and then click OK.  On the View menu, click Server Explorer. In the Server Explorer window, click Connect to Database.</li> Follow these steps in the Data Link Properties dialog box:  In the Select or enter a server name text box, type localhost .</li> Under Enter information to log on to the server, click Use Windows NT Integrated security.</li> Click Select the database on the server, and then select Northwind from the list of databases.</li> Click Test Connection to verify that the information is correct, and then click OK.</li></ol> </li> In the Server Explorer window, expand the Data Connections, the  .Northwind.dbo, and the Tables nodes.</li> Right-click Categories, and then click Retrieve Data from Table.</li> Edit one of the product descriptions, and then move to another record. Notice that this change affects the underlying data source.</li> Right-click Categories, and then click Design Table. Change the length of the CategoryName column to 20. Click Save, and then verify the table updates.</li> Right-click Views, and then click New View. Add the Customers table to the view, and then click OK to close the Add Table dialog box.</li> In the Customers table, select the following columns: <ul> CompanyName</li> ContactName</li> ContactTitle</li></ul>

</li> <li>Right-click in the SQL pane, and then click Verify SQL Syntax.</li> <li>Right-click in the diagram pane, and then click Run.</li> <li>Click Save, and then type CustomerInfo for the view.</li></ol>

back to the top

Display Data in a Windows Form
<ol> <li>View Form1 in the Design window.</li> <li>Drag the Categories node from the Server Explorer window to Form1, which adds the SqlConnection and the SqlDataAdapter objects to the form. View the properties of these objects to verify that they are configured to connect to the Categories table in the Northwind database.</li> <li>Right-click SqlDataAdapter1, and then click Generate Dataset. Click OK in the Generate Dataset dialog box.</li> <li>Add a DataGrid control to the form, and then set the DataSource property of the DataGrid to DataSet11.Categories.</li> <li> Create an event handler for the Form_Load event, and then add the following code to this event: SqlDataAdapter1.Fill(DataSet11) </li> <li>On the File menu, click Save All.</li> <li>Run the application, and then verify that the data is displayed correctly.</li></ol>

back to the top

<div class="references_section">