当前位置: 首页 > 图文教程 > 网络编程 > ASP.NET > SQL Server.net 和 OLE DB.net连接数据库的比较

ASP.NET
HTML服务器控件介绍:HtmlInputFile控件
HTML服务器控件介绍:HtmlInputHidden控件
HTML服务器控件介绍:HtmlInputImage控件
HTML服务器控件介绍:HtmlInputRadioButton控件
HTML服务器控件介绍:HtmlInputText控件
HTML服务器控件介绍:HtmlSelect控件
HTML服务器控件介绍:HtmlTable控件
HTML服务器控件介绍:HtmlTableCell控件
HTML服务器控件介绍:HtmlTableRow控件
HTML服务器控件介绍:HtmlTextArea控件
Web服务器控件:AdRotator控件
Web服务器控件:Button控件
Web服务器控件:Calendar控件
Web服务器控件:CheckBox控件
Web服务器控件:CheckBoxList控件
Web服务器控件:DropDownList控件
Web服务器控件:HyperLink控件
Web服务器控件:Image控件
Web服务器控件:ImageButton控件
Web服务器控件:Label控件

ASP.NET 中的 SQL Server.net 和 OLE DB.net连接数据库的比较


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 147 ::
收藏到网摘: n/a


ADO.net的数据库访问是他通过被称为"数据提供程序(data provider)"的软件模块进行的..net框架1.0版本是"分裂人格"的,就是他提供了两个数据提供程序:SQL Server.NET提供程序和OLE DB.NET提供程序.
SQL Server.NET提供程序 它是Microsoft SQL Server数据库的接口,不需要任何非托管提供程序的帮助.
OLE DB.NET提供程序 它是通过OLE DB提供程序访问数据库的接口.
下面简单介绍下他们在连接数据库上的区别:
下面的例子用SQL Server.NET提供程序程序列出包含在Pubs数据库的Titles表中的所有书名:
using System.Data.SqlClient;…… SqlConnection conn=new SqlConnection("server=localhost;uid=sa;pwd=;database=pubs"); try { conn = conn.Open (); SqlCommand command=new SqlCommand ("select * from titles",conn); SqlDataReader reader=command.ExecuteReader(); while(reader.Read()) { Console.WriteLine(reader["title"]); } } catch(SqlException e) { Console.WriteLine(e.ToString()); } finally { conn.Close(); }
下面用OLE DB.NET提供程序程序重新编写:
using System.Data.OleDb;…… OleDbConnection conn=new OleDbConnection("provider=sqloledb;server=localhost;uid=sa;pwd=;database=pubs");

try { conn = conn.Open (); OleDbCommand command=new OleDbCommand ("select * from titles",conn); OleDbDataReader reader=command.ExecuteReader(); while(reader.Read()) { Console.WriteLine(reader["title"]); } } catch(OleDbException e) { Console.WriteLine(e.ToString()); } finally { conn.Close(); }