How To: Create an ASP.NET Web Application using SqlDataSource Control

This topic provides step-by-step instructions on how to create a Web application that uses the SQL Server Compact database as a data source.

To Create a Web Application using SqlDataSource Control

  1. In Visual Studio, on the File menu, point to New, and then select Project.

  2. In the Project Types list of the New Project dialog box, expand the programming language you will use, and then select Visual C# or Visual Basic.

  3. In the Templates list, select ASP.NET Web Application.

  4. Provide a Name (such as SQLDataSourceWebApplication) and Location for your project, and then click OK.

  5. Switch to Design View by clicking on Design tab.

  6. In the Toolbox, expand the Data group , and then drag a SqlDataSource control onto the page.

  7. On the SqlDataSource Tasks shortcut menu on the control, click Configure Data Source.

  8. On the Choose Your Data Connection screen, click New Connection.

  9. In the Add Connection dialog box, click Change.

  10. In the Change Data Source dialog box, click Microsoft SQL Server Compact 4.0, browse to Northwind.sdf, and then click OK.

    Click Test connection to verify that the connection to the database succeeds.

  11. Notice that in the Configure Data Source - <Datasourcename> dialog box, your new connection is selected.

  12. Click Next.

  13. Select Yes, save this connection as box, enter a name for your connection for when the connection is stored in the application configuration file, and then click Next.

  14. Select the option Specify columns from a table or view, and then from the Name drop-down list, select the Customers table . Click Next.

  15. To test your query, click Test Query.

  16. Click Finish.

  17. Drag-and-drop the GridView data tool from the Toolbox onto the design tab.

  18. Click the GridView control, and open GridView Tasks.

  19. In Choose Data Source, select <Datasourcename> that you have created.

  20. Build the project by clicking Build Solution on the Project menu.

  21. Run the project. This new application you have created will pull data from the Customers table, and then display in the form of a Grid.

See Also

Other Resources

SqlDataSource