The item marked as 1 is a multi-line text-box control used to show the table schema shown in section 1 of this example. The Get Table Schema button (Marked as 2) displays the schema data of the discount table in the multi-line text box. Before using this example, one need to setup the connection string to the Pubs database. Setting the connection string for the NorthWnd database is shown in the below video. We can follow the same method to set the connection string for the Pubs database as the table DISCOUNTS resides in it. When you create Connection String name it as PUBSDB.
To fetch data from the database, we need DB connection. In ADO.Net, based on the Database Provider, there are distinct connection classes. For example, to hook up to an Oracle Database we need to use OracleConnection and in the same way we need SqlConnection to hook up to the SQL Server database. The Command Object is also database specific. For Example, SqlCommand object can talk with SQL Server DB through SqlConnection object and OracleCommand object can talks to the Oracle DB through OracleConnection. These command objects know what needs to be executed in the database. In this article, we will study how to use SqlCommand and its methods ExecuteScalar, ExecuteReader and ExecuteNonQuery.
In this Example, we will read employee information from SQL Server and display that in the ASP.Net Web Page using SqlCommand and SqlDataReader.