ADO.NET简介

转载 2006年06月03日 20:06:00

ADO.NET包括以下几个命名空间:

  • System.Data.SqlClient— Contains classes for connecting to Microsoft SQL Server version 7.0 or higher

  • System.Data.OleDb— Contains classes for connecting to a data source that has an OLE DB provider

  • System.Data.Odbc— Contains classes for connecting to a data source that has an ODBC driver

  • System.Data.OracleClient— Contains classes for connecting to an Oracle database server

 

NOTE

It is expected that additional data provider-specific namespaces will be released over time. Microsoft has already released a separate set of classes for working with Microsoft SQL Server in the Compact Framework, and a separate set of classes for working with XML generated from SQL Server 2000. For more information on these additional namespaces, see the msdn.microsoft.com Web site.

Oracle has also released their own namespace for working with Oracle databases. You can download the Oracle provider for .NET (ODP.NET) from the Oracle Web site.

 

Why did Microsoft duplicate these classes, creating different versions for different types of databases? By creating separate sets of classes, Microsoft was able to optimize the classes.

For example, the OleDb classes use OLE DB providers to connect to a database. The SQL classes, on the other hand, communicate with Microsoft SQL Server directly on the level of the Tabular Data Stream (TDS) protocol. TDS is the low-level proprietary protocol used by SQL Server to handle client and server communication. By bypassing OLE DB and ODBC and working directly with TDS, you get dramatic performance benefits.

NOTE

You can use the classes from the System.Data.OleDb namespace with Microsoft SQL Server. You might want to do so if you want your ASP.NET page to be compatible with any database. For example, you might want your page to work with both Microsoft SQL Server and Oracle. However, you lose all the speed advantages of the SQL- and Oracle-specific classes if you use the System.Data.OleDb namespace.

 

There are several ways you can create a new parameter and associate it with a Command. For example, the following two statements create and add a new parameter to the SqlCommand object:

 
cmdSelect.Parameters.Add( "@firstname", "Fred" )
cmdSelect.Parameters.Add( New SqlParameter( "@firstname", "Fred" ) )

These two statements are completely equivalent. Both statements create a new SqlParameter with the name @firstname and the value Fred and add the new parameter to the parameters collection of the SqlCommand object.

Notice that we do not specify the SQL data type of the parameter in the case of either statement. If you don't specify the data type, it is automatically inferred from the value assigned to the parameter. For example, since the value Fred is a String, the SQL data type NVarchar is inferred. In the case of an OleDbParameter, the data type VarWChar would be automatically inferred. 

In some cases, you'll want to explicitly specify the data type of a parameter. For example, you might want to explicitly create a Varchar parameter instead of an NVarchar parameter. To do this, you can use the following statement:

 
cmdSelect.Parameters.Add( "@lname", SqlDbType.Varchar ).Value = "Johnson"

This statement specifies the SQL data type of the parameter by using a value from the SqlDbType enumeration. The SqlDbType enumeration is located in the System.Data namespace. Each of its values corresponds to a SQL data type.

In the case of an OleDbParameter, you would use a value from the OleDbType enumeration like this:

 
cmdSelect.Parameters.Add( "@lname", OleDbType.Varchar ).Value = "Johnson"

The OleDbType enumeration can be found in the System.Data.OleDb namespace.

Finally, you can specify the maximum size of a database parameter by using the following statement:

 
cmdSelect.Parameters.Add( "@lname", SqlDbType.Varchar, 15 ).Value = "Johnson"

This statement creates a parameter named @lname with a column size of 15 characters.

If you don't explicitly specify the maximum size of a parameter, the size is automatically inferred from the value assigned to the parameter.

相关文章推荐

ADO.NET 本质论(PDG)简介

  • 2014-05-08 09:40
  • 6.57MB
  • 下载

ADO.NET简介

ADO.NET的名称起源于ADO(ActiveX Data Objects),这是一个广泛的类组,用于在以往的Microsoft技术中访问数据.之所以使用ADO.NET名称,是因为Microsoft希...

ADO.NET简介

简介: ADO.NET是微软新一代.NET数据库的访问架构,ADO.NET是数据库应用程序和数据源之间沟通的桥梁,主要提供一个面向对象的数据访问架构,用来开发数据库应用程序。 ADO.NET允许和...

ADO.NET两种连接模型简介及增删改查实例

ADO.NET支持两种访问数据的模型:无连接模型和连接模型         无连接模型:将数据下载到客户机器上,并在客户机上将数据封装到内存中,然后可以像访问本地关系数据库一样访问内存中的数据(例如D...

ADO.NET Entity Framework简介

下一代的ADO.NET的目标是要解决关系数据模型和实际应用程序需要模型之间的鸿沟,那么它是怎么做到的呢? 我们都知道,建立在关系数据库基础之上的应用程序经常需要在不同的表之间做复杂的join操作...

ADO.net 技术简介,doc文本

  • 2008-11-20 13:43
  • 139KB
  • 下载

ADO.NET 简介

  • 2008-11-18 08:44
  • 3.44MB
  • 下载

ado.net视频教程-实战开发CRM企业客户管理系统

ado.net视频教程-基于ASP.NET MVC3+ADO.NET4+EF4.1+Jquery+插件等技术下的CRM企业客户管理系统 ado.net视频教程项目简介: 客户是公司最宝贵的资源,为...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)