ADO.Net Tutorial for Beginners
Companies operating in today’s fast-paced, dynamic corporate world must ensure seamless data interactions and ensure reliable connectivity between various systems and applications.
ADO.NET provides strong data access technology which makes database integration simpler by making various data sources easier to integrate.
Data management is centralised via ADO.NET, providing an organized method for data operations management that enhances performance while eliminating intricate coding requirements.
As organisations adapt to new technologies, this allows them to connect and retrieve data from a variety of sources efficiently while guaranteeing scalability, high performance and ease of maintenance.
What Is ADO.NET?
The ADO.NET data access technology within the.NET framework enables programs to quickly and effectively connect and work with data from different sources – including databases – quickly and effectively.
Both connected and disconnected data models can be supported as well as tools for organizing, updating and querying.
How to Store Connection Strings in a Configuration File
Imagine some files point at one database while others point towards another – an extremely error prone setup! For this reason, it’s recommended to store these connection strings in a configuration file for safe keeping.
So if we have an A S P.N E T web application, this A SP.N E T application already contains web.config as its configuration file and we want to store our connection string in it, see this… it already is there.
Within the connection string element, we can create a meaningful name for our connection string; perhaps D B C S short database connection string would suffice?
Your connection string is just another means of specifying data sources or databases using its unique connection string name and string length.
Copy and paste that into our connection string property here, then provide a name such as system.data.
sqlFline since we will be communicating with SQL Server through it. Now we have stored our connection strings in web.config file!
So we can delete this particular line here; since it was stored in the configuration file, but our application needs to know about that connection string.

ADO.NET Training

purpose of S Q L command object and creating an instance of this S Q L command
So we simply use that as an argument when creating our SQ L connection object and store our connection string in web.config file for easy reference.
By doing this we also create an instance of this SQ L command object which acts like its counterpart – creating an instance of it each time we make calls against it.
Learn the purpose and functionality of an SQ L command object, create its instance and when and how to utilize its execute reader, execute scalar, and execute non-quary methods.
At first, we will demonstrate how to use the S Q L command class to prepare an SQL statement and execute it against a database.
Furthermore, we’ll show how stored procedures can also be executed using this class.
There are three commonly utilized methods within S Q L command class – reader execution, non-quarary execution and scalar execution methods.
So how do we tell our application to do that?
For this task, in the. N E T framework there exists a class called Configuration Manager which serves this function. As its name implies, this class will manage my app’s configuration settings.
Now we can use that class and then read the connection string from web.config file. Let’s use configuration manager as the class we will need – typing it here won’t find it though; system configuration contains it instead.
Even the name space is meaningful. Now we want to handle configuration from web.config file using system.configuration namespace’s configuration manager class.
Import system.configuration as we need a configuration manager within that namespace with connection strings property; using this will return all properties and connection strings that exist (it’s possible to have multiple connection strings in web.config file), while we only want DBCSS as one option.
Now we can specify either an integer index. Using zero will return you directly to the initial connection string, since we only have one instance available; but as best practice it would be best to name the connection string explicitly so we know which connection string we are referring to.
Let’s say DBCSS is our connection string name, with dot being our desired connection string value. Use that property or store in a variable and store that into string connection string that corresponds to that value.
Execute reader
Execute reader is typically used when we want to execute T S Q L statements that return multiple values; otherwise we use Execute nonquery; however if our query returns only a single value (known as scalar values), then Execute Scalar would be used instead.

ADO.NET Online Training

Non Query
Execute non query whenever your query performs an insert update or delete operation; when inserting, updating, or deleting, use non query instead of normal query to avoid data manipulation errors.
Let’s see how to do that. Let’s say we want to insert rose into this table; given all of its columns, and their values we have provided here for T B L product table values inserted.
Let’s write the query so it will insert rose into T B L product table values (where T is an identity column and L not).
Let’s provide the necessary values: Primary Key = 4, Product name is calculators and there may be up to 230 available Quantities – so obviously we want to execute this query; copy that out, copy out this command that we wish to execute (e.g. “open connection”) and paste in that copy as an insert row into an existing table (which could include adding columns and updating existing data sets), then open connection based on that connection name (open it if it exists already).
As this is an insert operation, we will instead use execute non query. IntelliSense displays its return type as integer when viewing this command: execute non query = insert operation
So why is execute non query returning an integer?
Simply, when we perform an insert update or delete, our database will tell us exactly how many rows have been inserted, updated or deleted by using an integer as its resultant number.
Example: If the query returns the total number of rows in a table, we can use execute scalar method. Or if we are trying to calculate average salaries of employees using Excel’s pay scale feature – both are single values which must be returned. Whenever our query returns a single value like these examples above, execute scalar is used instead.
Conclusion
ADO.NET is an integral data access technology of.NET programs, offering reliable ways of connecting, retrieving, and working with data. Businesses can utilize ADO.NET’s scalability, strong transaction management, support for both connected and unconnected data models as a basis for creating high-performance, data-driven apps.
Furthermore, ADO.NET serves as an indispensable tool for developers working with databases or other forms of data services as it manages multiple sources efficiently while optimizing processes related to them.

ADO.NET Course Price


G. Madhavi
Author