How To Use Visual Studio .NET Server Explorer to Access Data (304959)



The information in this article applies to:

  • Microsoft Visual Studio .NET (2003), Enterprise Architect Edition
  • Microsoft Visual Studio .NET (2003), Enterprise Developer Edition
  • Microsoft Visual Studio .NET (2003), Academic Edition
  • Microsoft Visual Studio .NET (2002), Professional Edition
  • Microsoft Visual Studio .NET (2002), Enterprise Architect Edition
  • Microsoft Visual Studio .NET (2002), Enterprise Developer Edition
  • Microsoft Visual Studio .NET (2002), Academic Edition

This article was previously published under Q304959

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

  1. Follow these steps to create a new Visual Basic Windows Application project:
    1. Start Visual Studio .NET.
    2. On the File menu, point to New, and then click Project.
    3. In the New Project dialog box, click Visual Basic Projects under Project Types, click Windows Application under Templates, and then click OK.
  2. On the View menu, click Server Explorer.
  3. In the Server Explorer window, click Connect to Database.
  4. Follow these steps in the Data Link Properties dialog box:
    1. In the Select or enter a server name text box, type localhost.
    2. Under Enter information to log on to the server, click Use Windows NT Integrated security.
    3. Click Select the database on the server, and then select Northwind from the list of databases.
    4. Click Test Connection to verify that the information is correct, and then click OK.
  5. In the Server Explorer window, expand the Data Connections, the YourServerName.Northwind.dbo, and the Tables nodes.
  6. Right-click Categories, and then click Retrieve Data from Table.
  7. Edit one of the product descriptions, and then move to another record. Notice that this change affects the underlying data source.
  8. 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.
  9. 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.
  10. In the Customers table, select the following columns:
    • CompanyName
    • ContactName
    • ContactTitle

  11. Right-click in the SQL pane, and then click Verify SQL Syntax.
  12. Right-click in the diagram pane, and then click Run.
  13. Click Save, and then type CustomerInfo for the view.
back to the top

Display Data in a Windows Form

  1. View Form1 in the Design window.
  2. 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.
  3. Right-click SqlDataAdapter1, and then click Generate Dataset. Click OK in the Generate Dataset dialog box.
  4. Add a DataGrid control to the form, and then set the DataSource property of the DataGrid to DataSet11.Categories.
  5. Create an event handler for the Form_Load event, and then add the following code to this event:
    SqlDataAdapter1.Fill(DataSet11)
    					
  6. On the File menu, click Save All.
  7. Run the application, and then verify that the data is displayed correctly.
back to the top

REFERENCES

For more information about accessing data, see the following topic in MSDN or the Visual Studio .NET Help documentation: For additional information about .NET data providers, click the article number below to view the article in the Microsoft Knowledge Base:

313480 INFO: Roadmap for .NET Data Providers

back to the top

Modification Type:MinorLast Reviewed:5/23/2005
Keywords:kbHOWTOmaster KB304959 kbAudDeveloper