Professional Documents
Culture Documents
Slide 1
Objectives
Applied Use a SQL data source to get the data that an application requires. Use the Query Builder to create the Select statement for a SQL data source. Use a DataList control to present the data thats retrieved by a SQL data source. Use a list control such as a drop-down list to present the data thats retrieved by a SQL data source. Use a SQL data source to update the data in a database.
Slide 2
Objectives (cont.)
Knowledge Describe how a select parameter that gets its value from a control is defined. Describe how you use the Eval and Bind methods within the templates of a DataList control to bind the template controls to columns of a data source. Describe the additional code thats generated for a data source that can update the database. Explain when you might change the DataSourceMode attribute of a data source from its default setting of DataSet to DataReader. Explain when you might want to store the data thats retrieved by a data source in the servers cache memory.
Slide 3
Slide 4
Slide 5
Slide 6
ProviderName SelectCommand
Slide 7
Slide 8
The dialog box for saving the connection string in the web.config file
Slide 9
Slide 10
Slide 11
Slide 12
Slide 13
Slide 14
The aspx code for a SqlDataSource control that includes a select parameter
<asp:SqlDataSource ConnectionString= "<%$ ConnectionStrings:HalloweenConnectionString %>" ID="SqlDataSource2" runat="server" SelectCommand= "SELECT [ProductID], [Name], [UnitPrice], [OnHand] FROM [Products] WHERE ([CategoryID] = @CategoryID) ORDER BY [ProductID]"> <SelectParameters> <asp:ControlParameter Name="CategoryID" Type="String" ControlID="ddlCategory" PropertyName="SelectedValue" /> </SelectParameters> </asp:SqlDataSource>
Slide 15
Slide 16
Slide 17
Slide 18
Slide 19
Parameter sources
Source Control QueryString Form Session Profile Cookie Description The parameters value comes from a control on the page. The parameters value comes from a query string in the URL used to request the page. The parameters value comes from an HTML form field. The parameters value comes from an item in session state. The parameters value comes from a profile property. The parameters value comes from a cookie.
Slide 20
Slide 21
Slide 22
A Header template
Slide 23
Slide 24
Slide 25
Slide 26
Slide 27
The aspx code for a drop-down list thats bound to a SQL data source
<asp:DropDownList ID="ddlCategory" runat="server" AutoPostBack="True" Width="130px" DataSourceID="SqlDataSource1" DataTextField="LongName" DataValueField="CategoryID"/> </asp:DropDownList>
Slide 28
Slide 29
Code examples
<%# Eval("Name") %> <%# Eval("UnitPrice", "{0:C}") %> <%# Bind("UnitPrice", "{0:C}") %>
Slide 30
Slide 31
Slide 32
Slide 33
Slide 34
Slide 35
Slide 36
The aspx code for a SqlDataSource control that uses action queries
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString= "<%$ ConnectionStrings:HalloweenConnectionString %>" SelectCommand="SELECT [CategoryID], [ShortName], [LongName] FROM [Categories]" InsertCommand="INSERT INTO [Categories] ([CategoryID], [ShortName], [LongName]) VALUES (@CategoryID, @ShortName, @LongName)" UpdateCommand="UPDATE [Categories] SET [ShortName] = @ShortName, [LongName] = @LongName WHERE [CategoryID] = @CategoryID"> DeleteCommand="DELETE FROM [Categories] WHERE [CategoryID] = @CategoryID" <DeleteParameters> <asp:Parameter Name="CategoryID" Type="String" /> </DeleteParameters>
Slide 37
The aspx code for a SqlDataSource control that uses action queries (continued)
<UpdateParameters> <asp:Parameter Name="ShortName" Type="String" /> <asp:Parameter Name="LongName" Type="String" /> <asp:Parameter Name="CategoryID" Type="String" /> </UpdateParameters> <InsertParameters> <asp:Parameter Name="CategoryID" Type="String" /> <asp:Parameter Name="ShortName" Type="String" /> <asp:Parameter Name="LongName" Type="String" /> </InsertParameters> </asp:SqlDataSource>
Slide 38
Slide 39
Slide 40
Slide 41