什么是 ADO.NET

发布于 2024-09-16 15:25:20 字数 143 浏览 6 评论 0原文

我对ADO.NET的理解很困惑,读了几篇文章后我并不清楚什么是性能考虑。

  • 什么是 ADO.NET?性能考虑因素又如何?
  • ADO.NET 可以与 SQL 存储过程相关联还是不同的东西?

谢谢你们!

I puzzled with understanding ADO.NET, after reading several articles I do not have a clear idea what is perfomance consideration.

  • What is ADO.NET and what about perfomance considerations?
  • ADO.NET could be associated with SQL STORED PROCEDURES or are different things?

Thanks guys!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

留一抹残留的笑 2024-09-23 15:25:25

什么是 ADO.NET?

一般来说,它是一种访问数据库(或其他类型的数据源,如 csv 文件)的技术。从程序员的角度来看,它只是一组库和类,他需要这些库和类来访问数据库及其数据库工件(如表、视图或存储过程)。

ADO.NET 可以与 SQL 存储过程相关联还是不同的东西?

您可以使用 ADO.NET 来访问一段托管代码(用 C# 或 VB 编写)中的存储过程。存储过程是驻留在数据库中的一段代码(用例如 PL/SQL 或 T-SQL 编写)。是的,它们是完全不同的东西。

What is ADO.NET?

In general it is a technology to access a database (or other kinds of datasources like a csv file). From the programmers point of view it is just a set of libraries and classes which he needs to get access to a database and its database artifacts (like tables, views or stored procedures).

ADO.NET could be associated with SQL STORED PROCEDURES or are different things?

You use ADO.NET in order to access a stored procedure in a piece of managed code (written in e.g. C# or VB). A stored procedure is a piece of code (written in e.g. PL/SQL or T-SQL), which resides on the database. Yes, they are completely different things.

可爱咩 2024-09-23 15:25:24

ADO.NET 是 .NET 框架的一部分,是数据库驱动程序和应用程序之间的层。 .NET 应用程序中的所有数据库访问都通过 ADO.NET。

数据库驱动程序通常是本机 .NET 驱动程序,但也可以是 ODBC 驱动程序之类的东西。

通过 ADO.NET 例程,您可以使用 SQL 查询、SQL 存储过程或直接表绑定来访问数据库。这些都是特定于数据库的,并且根据数据库和数据库驱动程序而有所不同,但是数据库有一个 SQL 标准进行扩展,因此至少有一些共同点。

您可以使用一些数据访问框架来代替 ADO.NET,例如实体框架。然而它们并没有取代ADO.NET,它们仍然使用ADO.NET层来访问数据库。

ADO.NET is the part of the .NET framework that is the layer between a database driver and your application. All database access in a .NET application goes though ADO.NET.

The database driver is usually a native .NET driver, but it can also be something like an ODBC driver.

Through the ADO.NET routines you can access the database either by using SQL queries, SQL stored procedures, or direct table binding. These are all database specific and varies depending on the database and database driver, however there is a SQL standard that databases expand upon, so there is at least some common ground.

There are data access frameworks that you can use instead of ADO.NET, like the Entity Framework. However they don't replace the ADO.NET, they still use the ADO.NET layer to access the database.

平生欢 2024-09-23 15:25:23

Ado.net 视为一个托管库,它提供访问外部数据源所需(并可能使用)的所有类和功能。这是最简单的思考方式。但由于它不是一个单独的库(因为它包含在 .net 库中),人们往往会感到困惑。我们可以说它是.net 中的一个库。

更全面的解释可以在维基百科上找到。

存储过程是特定数据存储的一部分。 Ado.net 使您能够以标准化方式调用这些存储过程。

来自 MSDN 的示例

using (SqlConnection connection = new SqlConnection(connectionString))
{
    // Create the Command and Parameter objects.
    SqlCommand command = new SqlCommand(queryString, connection);
    command.Parameters.AddWithValue("@pricePoint", paramValue);

    // Open the connection in a try/catch block. 
    // Create and execute the DataReader, writing the result
    // set to the console window.
    try
    {
        connection.Open();
        SqlDataReader reader = command.ExecuteReader();
        while (reader.Read())
        {
            Console.WriteLine("\t{0}\t{1}\t{2}", reader[0], reader[1], reader[2]);
        }
        reader.Close();
    }
    catch (Exception ex)
    {
        Console.WriteLine(ex.Message);
    }
    Console.ReadLine();
}

您可以看到 Ado.net 类的使用:

  • SqlConnection
  • SqlCommand
  • SqlDataReader

所以 Ado.net 为您提供了所有这些,因此您不必每次想要访问外部数据源(关系数据库、服务等)时都重新发明轮子。

Think of Ado.net as a managed library that provides all the classes and functionality you need (and may use) to access external data sources. That's the most simplest way of thinking of it. But since it's not a separate library (because it's included with the .net library) people tend to be confused. We could say it's a library inside .net.

A more thorough explanation can be found on Wikipedia.

Stored procedure is part of a particular data store. Ado.net gives you the ability to call these stored procedures in a standardized way.

An example from MSDN

using (SqlConnection connection = new SqlConnection(connectionString))
{
    // Create the Command and Parameter objects.
    SqlCommand command = new SqlCommand(queryString, connection);
    command.Parameters.AddWithValue("@pricePoint", paramValue);

    // Open the connection in a try/catch block. 
    // Create and execute the DataReader, writing the result
    // set to the console window.
    try
    {
        connection.Open();
        SqlDataReader reader = command.ExecuteReader();
        while (reader.Read())
        {
            Console.WriteLine("\t{0}\t{1}\t{2}", reader[0], reader[1], reader[2]);
        }
        reader.Close();
    }
    catch (Exception ex)
    {
        Console.WriteLine(ex.Message);
    }
    Console.ReadLine();
}

You can see the use of Ado.net classes:

  • SqlConnection
  • SqlCommand and
  • SqlDataReader

So Ado.net has all these provided for you, so you don't have to reinvent the wheel every time you'd like to access external data sources (relational data bases, services etc.).

分開簡單 2024-09-23 15:25:22

ADO.NET 是 .NET 框架的一个组件,允许您访问不同的数据源。存储过程则不同:它是一个允许您查询关系数据库并在数据库内部运行的函数。

因此,您可以使用 ADO.NET 来调用存储过程。以以下为例:

using (var con = new SqlConnection(SomeConnectionStringToTheDatabase))
using (var cmd = con.CreateCommand())
{
    con.open();
    con.CommandText = "NameOfTheStoredProcdureYouWantToInvoke";
    con.CommandType = CommandType.StoredProcedure;

    var result = command.ExecuteNonQuery();
}

SqlConnection、我们用来调用的SqlCommand存储过程是 ADO.NET 的一部分。

ADO.NET is a component of the .NET framework that allows you to access different data sources. A stored procedure is different: it is a function that allows you to query a relational database and which runs inside the database.

So you could use ADO.NET to call a stored procedure. Take for example the following:

using (var con = new SqlConnection(SomeConnectionStringToTheDatabase))
using (var cmd = con.CreateCommand())
{
    con.open();
    con.CommandText = "NameOfTheStoredProcdureYouWantToInvoke";
    con.CommandType = CommandType.StoredProcedure;

    var result = command.ExecuteNonQuery();
}

The classes SqlConnection, SqlCommand that we use to call the stored procedure are part of ADO.NET.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文