Presentation is loading. Please wait.

Presentation is loading. Please wait.

ADO.NET Data Access. Page  2 SQL  When we interact with the datasource through ADO.NET we use the SQL language to retrieve,modify,update information.

Similar presentations


Presentation on theme: "ADO.NET Data Access. Page  2 SQL  When we interact with the datasource through ADO.NET we use the SQL language to retrieve,modify,update information."— Presentation transcript:

1 ADO.NET Data Access

2 Page  2 SQL  When we interact with the datasource through ADO.NET we use the SQL language to retrieve,modify,update information  Structured Query Language is a standard data access language used to interact with relational database  SQL Select Statement  Update Statement  Insert Statement  Delete Statement www.tech.findforinfo.com

3 Page  3 SQL Select Statement  To retrieve one or more rows of data the select command is used SELECT [columns] FROM [tables] WHERE [search_condition] ORDER BY [order_expression ASC | DESC] www.tech.findforinfo.com

4 Page  4 Sample Select Statement (eg) SELECT * FROM Authors  (*) - retrieves all the columns from the table  The FROM clause identifies that the Author table is being used  There is no WHERE clause, means all the records will be retrieved  There is no ORDER BY clause, means the data’s are not sorted www.tech.findforinfo.com

5 Page  5 Improving the Select Statement SELECT lname,fname FROM Authors WHERE State =‘MI’ ORDER BY lname ASC  Only two columns are retrieved  WHERE Clause provides the restriction to a particular state  An ORDER BY clause sorts the lname alphabetically in ascending order www.tech.findforinfo.com

6 Page  6 The WHERE clause (eg)SELECT * FROM Sales WHERE ord_date ‘1987/01/01’  Multiple conditions can be combined using the AND keyword  Greater than and Less than comparisons can be made using symbols www.tech.findforinfo.com

7 Page  7 SQL Update Statement  Syntax: Eg UPDATE Authors SET lname=‘Gowri’ WHERE id =‘101’ UPDATE [table] SET [update_epression] WHERE [search_condition] www.tech.findforinfo.com

8 Page  8 SQL Insert Statement  Syntax Eg INSERT INTO Authors (lname,fname) VALUES (‘John’,’Khan’) INSERT INTO [table] ([column_list]) VALUES ([value_list]) www.tech.findforinfo.com

9 Page  9 The SQL Delete Statement  Syntax  Eg DELETE FROM Authors WHERE id=‘102 DELETE FROM [table] WHERE [search_condition] www.tech.findforinfo.com

10 Page  10 Simple Data Access  To retrieve information with simple Data Access follow these steps  Create Connection,Command,DataReader objects  Use DataReader to retrieve information from the database and display it in a control in the webform  Close your connection  Send the page to the user.At this point all the connections have been closed www.tech.findforinfo.com

11 Page  11 Importing Namespaces  Imports System.Data  Imports System.Data.OleDb (OR)  Imports System.Data.SqlClient www.tech.findforinfo.com

12 Page  12 Creating a connection  The first step is to make a connection with the database  Specify a value for the ConnectionString property  This property defines all the information the computer needs to find the data source,log in and initial database www.tech.findforinfo.com

13 Page  13 The Connection String  The ConnectionString is actually a series of distinct pieces of information,separated by semicolons(;)  Provider –This refers to the name of the Provider which allows communication between ADO.NET and database (SQLOLEDB is the provider for SQL)  Data Source – This refers to the name of the server where the data source is located;Server is on the same computer so localhost www.tech.findforinfo.com

14 Page  14 The Connection String  Initial CataLog – It refers to the name of the initial database  User ID – Used to access the database,sa refers to the system admin account  Password - By default the ‘sa’ account does not have a password  ConnectionTimeout – It determines how long your code will wait in seconds before generating an error if it cannot establish connection default 15 seconds www.tech.findforinfo.com

15 Page  15 SQl Server Integrated Authentication  With SQL Server Authentication SQL Server maintains its own user account With integrated authentication SQL Server automatically uses the windows account information for the currently logged in user www.tech.findforinfo.com

16 Page  16 Making the connnection www.tech.findforinfo.com

17 Page  17 Defining a select command  The connection object a few basic properties that give the information about the connection  An SQL Statement that selects the information you want (eg) SELECT * from Authors  A command object that executes the SQL statement SqlDataAdapter adap=new SqlDataAdapter(“SELECT * from Author”,con)  A DataSet object to store the retrieved objects (eg)DataSet ds=new DataSet() www.tech.findforinfo.com


Download ppt "ADO.NET Data Access. Page  2 SQL  When we interact with the datasource through ADO.NET we use the SQL language to retrieve,modify,update information."

Similar presentations


Ads by Google