Difference between revisions of "SqlDataSource Demo"
esse quam videri
m (Text replacement - "<csharp>" to "<syntaxhighlight lang="csharp" line="1" >") |
m (Text replacement - "syntaxhighlight lang="csharp" line="1" " to "syntaxhighlight lang="csharp"") |
||
Line 25: | Line 25: | ||
Choose the table a fields you would like in the dataSource this will be added as the SelectCommand property | Choose the table a fields you would like in the dataSource this will be added as the SelectCommand property | ||
− | <syntaxhighlight lang="csharp | + | <syntaxhighlight lang="csharp"> |
SelectCommand="SELECT [userID], [firstName], [lastName], [recCreationDate] FROM [temp_user]" | SelectCommand="SELECT [userID], [firstName], [lastName], [recCreationDate] FROM [temp_user]" | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Line 38: | Line 38: | ||
The wizard should have added the following code you your page | The wizard should have added the following code you your page | ||
− | <syntaxhighlight lang="csharp | + | <syntaxhighlight lang="csharp"> |
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:tempCheeseTempUserConnectionString %>" | <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:tempCheeseTempUserConnectionString %>" | ||
SelectCommand="SELECT [userID], [firstName], [lastName], [recCreationDate] FROM [temp_user]"> | SelectCommand="SELECT [userID], [firstName], [lastName], [recCreationDate] FROM [temp_user]"> | ||
Line 48: | Line 48: | ||
Your web.config should look somehting like this | Your web.config should look somehting like this | ||
− | <syntaxhighlight lang="csharp | + | <syntaxhighlight lang="csharp"> |
<configuration> | <configuration> | ||
<system.web> | <system.web> |
Latest revision as of 03:21, 9 February 2016
Demo Add an SqlDataSource in VS2005
Drag an SqlDataSource object onto the Design view.
Click the arrow in the corner and slect Configure Data Source to start the wizard
Press new Connection
Enter info
Save Data Source this will update web.config so the Data Source will be reusable.
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]"
Click Test Query to test your query then click finish
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>