May 13, 2021 ASP.NET
ASP.NET allow access to and use of the following data sources:
ASP.NET hides complex data access processes and provides more advanced classes and objects that make access to their data easier. T hese classes hide all the complex code for connections, data access, data retrieval, and data manipulation.
ADO.NET technology provides a variety ASP.NET bridge between control objects and background data. I n this guide, we look at data access and briefly describe data.
Retrieving and ASP.NET data in the database requires two types of data control:
We'll explore data constraints and data source control in more detail later. I n this section, we'll apply the SqlDataSource control to access the data. D isplay and manipulate data with GridView controls in this chapter.
We'll also apply the Access database, which contains details of .Net books on the market. N ame our database ASPDotNetStepByStep.mdb and we'll apply a data table called DotNetReferences.
This table contains the following columns: ID, Title, AuthorFirstName, AuthorLastName, Topic, and Publisher.
The following image is a screenshot of this data table:
Let's follow these steps directly:
(1) Create a website and add SqlDataSourceControl to the web table.
(2) Click the Configure Data Source option.
(3) Click the New Connect button to establish a database connection.
(4) Once the connection is established, you can save them for later application. N ext, you'll be asked to set select statement:
(5) After selecting the items in the columns, click the next button to complete the remaining steps. O bserve where, ORDER BY, and Advanced buttons. T hese buttons allow you to execute where clauses, order by clauses, and specify insert, update, and delete commands in SQL, respectively. T his allows you to manipulate the data.
(6) Add a GridView control to the table. S elect the data source and build the control with the AutoFormat option.
(7) After that, the GridView control you set up can display the column title, and the program can execute.
(8) Final implementation of the procedure.
The codes involved above are listed below:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="dataaccess.aspx.cs"
Inherits="datacaching.WebForm1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>
Untitled Page
</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString= "<%$ ConnectionStrings:ASPDotNetStepByStepConnectionString%>"
ProviderName= "<%$ ConnectionStrings:
ASPDotNetStepByStepConnectionString.ProviderName %>"
SelectCommand="SELECT [Title], [AuthorLastName],
[AuthorFirstName], [Topic] FROM [DotNetReferences]">
</asp:SqlDataSource>
<asp:GridView ID="GridView1" runat="server"
AutoGenerateColumns="False" CellPadding="4"
DataSourceID="SqlDataSource1" ForeColor="#333333"
GridLines="None">
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<Columns>
<asp:BoundField DataField="Title" HeaderText="Title"
SortExpression="Title" />
<asp:BoundField DataField="AuthorLastName"
HeaderText="AuthorLastName" SortExpression="AuthorLastName" />
<asp:BoundField DataField="AuthorFirstName"
HeaderText="AuthorFirstName" SortExpression="AuthorFirstName" />
<asp:BoundField DataField="Topic"
HeaderText="Topic" SortExpression="Topic" />
</Columns>
<FooterStyle BackColor="#5D7B9D"
Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775"
ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#E2DED6"
Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True"
ForeColor="White" />
<EditRowStyle BackColor="#999999" />
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
</asp:GridView>
</div>
</form>
</body>
</html>