37 ADO.NET

What’s In This Chapter?

  • Connecting to the database
  • Executing commands
  • Calling stored procedures
  • The ADO.NET object model

Wrox.com Code Downloads for This Chapter

The wrox.com code downloads for this chapter are found at www.wrox.com/go/professionalcsharp6 on the Download Code tab. The code for this chapter is divided into the following major examples:

  • ConnectionSamples
  • CommandSamples
  • AsyncSamples
  • TransactionSamples

ADO.NET Overview

This chapter discusses how to access a relational database like SQL Server from your C# programs using ADO.NET. It shows you how to connect to and disconnect from a database, how to use queries, and how to add and update records. You learn the various command object options and see how commands can be used for each of the options presented by the SQL Server provider classes; how to call stored procedures with command objects; and how to use transactions.

ADO.NET previously shipped different database providers: a provider for SQL Server and one for Oracle, using OLEDB and ODBC. The OLEDB technology is discontinued, so this provider shouldn’t be used with new applications. Accessing the Oracle database, Microsoft’s provider is discontinued as well because a provider from Oracle (http://www.oracle.com/technetwork/topics/dotnet/) better fits the needs. For other data sources (also for Oracle), many third-party providers are available. Before using the ODBC provider, you should use a provider specific for the data source you access. The ...

Get Professional C# 6 and .NET Core 1.0 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.