Database Programming - Core Data Controls
Database Programming - Core Data Controls
Local DB
ConnectionString=
“Data Source=.\SQLEXPRESS; AttachDbFilename=|
DataDirectory|MyDatabase.mdf; Integrated
Security=True;
User Instance=True”
Working with SqlDataSource
Creating Database Connections
Server DB
ConnectionString=“
Data Source=ServerName;
Initial Catalog= DatabaseName;
User ID=SQLServerUserName;
Password=Password”
Working with SqlDataSource
Connecting to Other Databases-Oracle
The .NET Framework includes the following providers:
System.Data.OracleClient—Use the ADO.NET
provider for Oracle when connecting to an Oracle
database.
System.Data.OleDb—Use the OLE DB provider when
connecting to a data source that supports an OLE DB
provider.
System.Data.Odbc—Use the ODBC provider when
connecting to a data source with an ODBC driver.
Working with SqlDataSource
Connecting Oracle Database
<asp:SqlDataSource id=“srcOrders”
ProviderName=“System.Data.OracleClient”
SelectCommand=“SELECT * FROM Orders”
ConnectionString=“Data Source=OracleDB;
Integrated Security=yes” Runat=“server” />
There are three main types of DataBound
controls:
List DataBound Controls
EmptyDataText=”<img src=’sad.gif’/> No
Matching Movies!”
GridView Control
-Selecting Data
enable a user to select a particular row in
a GridView control. This is useful when
you want to build single-page
Master/Details forms.
first GridView has its
AutoGenerateSelectButton property
enabled. When this property has the value
True, a Select link is displayed next to
each row.
GridView Control
-Selecting Data
We can determine which row is selected in
a GridView control by using any of the
following methods:
SelectedDataKey()—Returns the DataKey
object associated with the selected row (useful
when there are multiple data keys).
SelectedIndex()—Returns the (zero-based)
index of the selected row.
SelectedValue()—Returns the data key
associated with the selected row.
GridView Control
-Selecting Data
Data Keys
We associate a value with each row in a
GridView by providing a value for the
GridView control’s DataKeyNames
property. We can assign the name of a
single database column to this property or
we can assign a comma-separated list of
column names to this property.
GridView Control
-Sorting Data
We can sort the rows rendered by a
GridView control by enabling the
AllowSorting property.
GridView Control
-Paging Through Data
When working with a large number of
database rows, it is useful to be able to
display the rows in different pages. We
can enable paging with the GridView
control by enabling its AllowPaging
property.
AllowPaging=”true” PageSize=”5”
GridView Control
- Customizing Paging
Customizing the Paging Interface By default, when
paging is enabled, the GridView renders a list of page
numbers at the bottom of the grid. We can modify the
user interface for paging through records by modifying
the GridView control’s PagerSettings property.
PageSize=”3”
PagerSettings-Mode=”NextPreviousFirstLast”
PagerSettings-Position=”TopAndBottom”
PagerStyle-HorizontalAlign=”Center”
GridView Control
- PagerSettings class
The PagerSettings class supports the following properties:
FirstPageImageUrl—Enables you to display an image for the first page link.
FirstPageText—Enables you to specify the text for the first page link.
LastPageImageUrl—Enables you to display an image for the last page link.
LastPageText—Enables you to specify the text for the last page link.
Mode—Enables you to select a display mode for the pager user interface. Possible
values are NextPrevious, NextPreviousFirstLast, Numeric, and NumericFirstLast.
NextPageImageUrl—Enables you to display an image for the next page link.
NextPageText—Enables you to specify the text for the next page link.
PageButtonCount—Enables you to specify the number of page number links to
display.
Position—Enables you to specify the position of the paging user interface. Possible
values are Bottom, Top, and TopAndBottom.
PreviousPageImageUrl—Enables you to display an image for the previous page
link.
PreviousPageText—Enables you to specify the text for the previous page link.
Visible—Enables you to hide the paging user interface.
Storing Connection in Web.config
Storing connection string in webpages
unsafe.
◦ Security
◦ Performance
◦ Difficult to manage
So better to store connection in configuration
file of Project
Storing Connection in Web.config
Web.Config;
<configuration>
<connectionStrings>
<add name=”Movies” connectionString=”Data
Source=.\SQLEXPRESS;
AttachDbFilename=|DataDirectory|
MyDatabase.mdf;Integrated Security=True;
User Instance=True” />
</connectionStrings>
</configuration>