小编典典

什么是ADO.NET

sql

在阅读了几篇文章之后,我对理解ADO.NET感到困惑。

  • 什么是ADO.NET?有关性能的注意事项如何?
  • ADO.NET可以与SQL STORED PROCEDURES关联,还是不同的东西?

谢谢你们!


阅读 254

收藏
2021-03-10

共1个答案

小编典典

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

可以在Wikipedia上找到更详尽的解释。

存储过程是特定数据存储的一部分。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为您提供了所有这些功能,因此您不必每次都要访问外部数据源(关系数据库,服务等)时就重新发明轮子。

2021-03-10