Difference between revisions of "SqlDataSource Demo"

esse quam videri
Jump to: navigation, search
m (Text replacement - "</csharp>" to "</syntaxhighlight>")
Line 27: Line 27:
 
<csharp>
 
<csharp>
 
SelectCommand="SELECT [userID], [firstName], [lastName], [recCreationDate] FROM [temp_user]"
 
SelectCommand="SELECT [userID], [firstName], [lastName], [recCreationDate] FROM [temp_user]"
</csharp>
+
</syntaxhighlight>
  
 
[[Image:6GridView ConfigureSelectStatement.png]]
 
[[Image:6GridView ConfigureSelectStatement.png]]
Line 42: Line 42:
 
             SelectCommand="SELECT [userID], [firstName], [lastName], [recCreationDate] FROM [temp_user]">
 
             SelectCommand="SELECT [userID], [firstName], [lastName], [recCreationDate] FROM [temp_user]">
 
</asp:SqlDataSource>
 
</asp:SqlDataSource>
</csharp>
+
</syntaxhighlight>
  
 
It also adds the connection to your web.config file
 
It also adds the connection to your web.config file
Line 57: Line 57:
 
</connectionStrings>
 
</connectionStrings>
 
</configuration>
 
</configuration>
</csharp>
+
</syntaxhighlight>

Revision as of 18:18, 25 January 2016


Demo Add an SqlDataSource in VS2005

Drag an SqlDataSource object onto the Design view.

1GridView ChangeToDesignAddSQLDataSource.png

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

2GridView ConfigureDataSource.png

Press new Connection

3GridView NewConnection.png

Enter info

4GridView AddConnection.png

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

5GridView SaveDataSource.png

Choose the table a fields you would like in the dataSource this will be added as the SelectCommand property <csharp> SelectCommand="SELECT [userID], [firstName], [lastName], [recCreationDate] FROM [temp_user]" </syntaxhighlight>

6GridView ConfigureSelectStatement.png

Click Test Query to test your query then click finish

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 <csharp> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:tempCheeseTempUserConnectionString %>"

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

</asp:SqlDataSource> </syntaxhighlight>

It also adds the connection to your web.config file

Your web.config should look somehting like this

<csharp> <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> </syntaxhighlight>