Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 10 Managing Data with ASP.NET. ASP.NET 2.0, Third Edition2.

Similar presentations


Presentation on theme: "Chapter 10 Managing Data with ASP.NET. ASP.NET 2.0, Third Edition2."— Presentation transcript:

1 Chapter 10 Managing Data with ASP.NET

2 ASP.NET 2.0, Third Edition2

3  To maintain a database you must be able to create new records, modify existing records, and delete records  You can accomplish this by using SQL commands or by using the methods built into the Data controls  You either can use the Command Builder method built into the GridView, DataList, and Repeater controls to help you build methods and procedures to maintain the database, or you can create your own methods to interact with the Data controls and database ASP.NET 2.0, Third Edition3

4  The InsertItemTemplate template is used to display the bound data in a read-only format  However, you can modify the template to change how the data is displayed  The EditItemTemplate template is used to format the controls that are available in edit mode  The SelectedItemStyle identifies the style for the currently selected row  The EditItemStyle identifies the style for the row that is currently being edited ASP.NET 2.0, Third Edition4

5  Parameters passed to the Select statement are called SelectParameter objects and are collectively called the SelectParameters collection  There are also InsertParameter, UpdateParameter, DeleteParameter, and FilterParameter objects for the insert, update, delete, and filter queries  ControlParameter: Allows you to retrieve the value from a property of a server control on a web page using the PropertyName property ASP.NET 2.0, Third Edition5

6  CookieParameter: Allows you to retrieve the value from an HTTP cookie using the CookieName property  FormParameter: Allows you to retrieve the value from a form control on a web page using the FormField property  ProfileParameter: Allows you to retrieve the value from the user profile using the ParameterName property  QueryStringParameter: Allows you to retrieve the value from a QueryString using the QueryStringField property  SessionParameter: Allows you to retrieve the value from a Session variable using the SessionField property ASP.NET 2.0, Third Edition6

7  The FilterParameter object is set to the value of a parameter used in a FilterExpression  The FilterParameter is defined in the DataSource control as a Parameter object  Both the FilterExpression property and FilterParameter object can be defined within the DataSource object or programmatically  Filtering data only is supported if the Select statement returns a DataSet, DataTable, or DataView object but not with the DataReader object ASP.NET 2.0, Third Edition7

8 8

9 9

10 10

11  By default, each column heading in the GridView control will be displayed as a hyperlink when sorting is enabled  Then, for each bound column in the GridView control, assign the SortExpression property to the name of the column that you want to be sorted  Usually the value of the SortExpression property is the same as the DataField property ASP.NET 2.0, Third Edition11

12 ASP.NET 2.0, Third Edition12

13 ASP.NET 2.0, Third Edition13

14 ASP.NET 2.0, Third Edition14

15 ASP.NET 2.0, Third Edition15

16 ASP.NET 2.0, Third Edition16

17 ASP.NET 2.0, Third Edition17

18  Set the deleting and inserting in the Task List for the GridView control  Although you can create code to insert a new record with the GridView control, the ShowInsertButton for the control is set to False by default  Using the insert methods with the GridView control would require additional programming and is not as flexible as using the DetailsView control to insert a new record ASP.NET 2.0, Third Edition18

19 ASP.NET 2.0, Third Edition19

20  You can bind data sources to a FormView control to insert, edit, and delete records  You can use the pager row to allow users to page through each record to locate the record that they want to edit  With large record sets, however, this is impractical; therefore, you should learn how to bind a value returned from the Data control to the query for retrieving a record in the FormView control  The FormView DefaultMode property can be set inside of the FormView tag; the CurrentMode property is used to identify the current mode  You can also change the mode programmatically; you can assign the value using the ChangeMode method of the FormView control ASP.NET 2.0, Third Edition20

21 ASP.NET 2.0, Third Edition21

22 ASP.NET 2.0, Third Edition22

23 ASP.NET 2.0, Third Edition23

24  Stored procedures are SQL queries that are stored with the database and can be reused; t hey can contain SQL commands and can be as simple as a Select statement.  Stored procedures are queries that reside on the database server, and because they are compiled by the database server, they are more efficient  Both AccessDataSource and SqlDataSource controls can be configured to pass parameters to an SQL query or to a stored procedure  SQL statements can be saved as a stored procedure and executed at a later time  When the stored procedure is called, you can then pass the value of the parameter ASP.NET 2.0, Third Edition24

25 ASP.NET 2.0, Third Edition25

26 ASP.NET 2.0, Third Edition26

27 ASP.NET 2.0, Third Edition27

28 ASP.NET 2.0, Third Edition28

29 ASP.NET 2.0, Third Edition29

30 ASP.NET 2.0, Third Edition30

31 ASP.NET 2.0, Third Edition31

32 ASP.NET 2.0, Third Edition32

33 ASP.NET 2.0, Third Edition33

34 ASP.NET 2.0, Third Edition34

35 ASP.NET 2.0, Third Edition35

36  SQL injection is a technique that is used by hackers to attach SQL statements to an existing SQL query in order to run additional commands  When a user enters data within a text box that is combined with an SQL statement, the hacker can insert additional SQL statements within that text box.; this action injects the hacker’s own SQL commands  To prevent SQL injection, always use stored procedures with sensitive data  Secure your SQL Server database by not leaving your password blank and by using a strong password; a strong password uses a combination of numbers and special characters to make it more difficult to guess ASP.NET 2.0, Third Edition36

37  If the record is not added successfully and an exception is triggered, the web page can catch the exception as an Exception object  The Exception object contains information about the error, such as the exception number, which helps you determine the type of error that occurred  The Try-Catch construct allows you to place code in the Try section that you want to execute  If an exception is thrown within this code, the code within the Catch section runs; the exception can be caught and stored as an object in a variable  You can access the exception number using the Number property of the Exception object ASP.NET 2.0, Third Edition37

38 ASP.NET 2.0, Third Edition38

39  Data controls can be bound to a variety of data sources. You can dynamically display the data by controlling when the BindData method is called. You can bind all of the controls at once or do so individually.  Data can be filtered using the SQL statement with the WHERE clause, or by using a parameter, such as a FilterParameter, or by using the FilterExpression property.  The EditItemTemplate property is used to format the controls that are available in edit mode. The EditItemStyle identifies the style for the row that currently is being edited. You can bind the controls by using a variety of controls such as the TemplateField, HyperLinkField, and CheckBoxField. ASP.NET 2.0, Third Edition39

40  The CommandField contains an Edit, Update, and Cancel hyperlink for editing, deleting, and canceling your editing requests. You can change the hyperlink to a button with the ButtonType property. You need to enable editing and deleting for the GridView control. The methods are built into the control, however. Therefore, you do not have to write custom code for basic web database management.  The DetailsView or FormView controls should be used for inserting new records instead of the GridView control. The InsertTemplate is used to configure the columns and values to insert into the new record. ASP.NET 2.0, Third Edition40

41  The DefaultMode for the FormView control is ReadOnly. You can programmatically modify the mode using the ChangeMode method, or by explicitly modifying the DefaultMode or CurrentMode property.  Stored procedures can improve efficiency within your program, decrease maintenance requirements, decrease design time errors, and improve data integrity and security.  Data controls can be bound to a variety of data sources. You can dynamically display the data by controlling when the BindData method is called. You can bind all of the controls at once or do so individually.  Data security is one aspect that should be included in your company information systems security policy. SQL injection is a technique that is used by hackers to attach SQL statements to an existing SQL query in order to run additional commands.  Try-Catch can help identify and handle errors with database applications. ASP.NET 2.0, Third Edition41


Download ppt "Chapter 10 Managing Data with ASP.NET. ASP.NET 2.0, Third Edition2."

Similar presentations


Ads by Google