Go to Content
Columbia College Chicago
IAM Wiki: SqlDataSource Demo
SqlDataSource Demo


Demo Add an SqlDataSource in VS2005

Drag an SqlDataSource object onto the Design view.

Image:1GridView ChangeToDesignAddSQLDataSource.png

Click the arrow in the corner and slect Configure Data Source to start the wizard

Image:2GridView ConfigureDataSource.png

Press new Connection

Image:3GridView NewConnection.png

Enter info

Image:4GridView AddConnection.png

Save Data Source this will update web.config so the Data Source will be reusable.

Image:5GridView SaveDataSource.png

Choose the table a fields you would like in the dataSource this will be added as the SelectCommand property

 
SelectCommand="SELECT [userID], [firstName], [lastName], [recCreationDate] FROM [temp_user]"

Image:6GridView ConfigureSelectStatement.png

Click Test Query to test your query then click finish

Image:7GridView TestQuery.png

Done if you want to rerun the wizard just perss the little arrow again.

The wizard should have added the following code you your page

 
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:tempCheeseTempUserConnectionString %>"
            SelectCommand="SELECT [userID], [firstName], [lastName], [recCreationDate] FROM [temp_user]">
</asp:SqlDataSource>

It also adds the connection to your web.config file

Your web.config should look somehting like this

 
<configuration>
    <system.web>
        <customErrors mode="Off"/>
    </system.web>
    <connectionStrings>
		<add name="tempCheeseTempUserConnectionString" connectionString="Data Source=iamdb;Initial Catalog=tempCheese;Persist Security Info=True;User ID=student;Password=Student" providerName="System.Data.SqlClient"/>
	</connectionStrings>
</configuration>
This page was last modified on 4 August 2008, at 20:56. This page has been accessed 1,238 times. About IAMMediaWiki Powered by MediaWiki