asp.net connection database compare bewteen ado.net Managed provider to ado.net sql managed provider

 

ADO.NET Managed Provider

ADO.NET SQL Managed Provider

需要引入的Namespace

System.Data.ADO

System.Data.SQL

Connection对象

ADOConnection

SQLConnection

Command对象

ADODatasetCommand

SQLDatasetCommand

Dataset对象

Dataset

Dataset

DataReader

ADODataReader

SQLDataReader

连接数据库例子

String sConnectionString = "Provider= SQLOLEDB.1;

Data Source=localhost;

uid=sa; pwd=; Initial Catalog=pubs";

 

ADOConnection con = new ADOConnection(sConnectionString);

con.Open();

String sConnectionString = "server=localhost;uid=sa;pwd=;database=pubs";

SQLConnection con = new SQLConnection(sConnectionString);

con.Open();

 

执行SQL语句例子

ADOCommand cmd = new ADOCommand("SELECT * FROM Authors", con);

ADODataReader dr = new ADODataReader();

cmd.Execute(out dr);

SQLCommand cmd = new SQLCommand(("SELECT * FROM Authors", con);

SQLDataReader dr = new SQLDataReader();

cmd.Execute(out dr);

使用存储过程例子

ADOCommand cmd = new ADOCommand ("spGetAuthorByID", con);

cmd.CommandType = CommandType.StoredProcedure;

 

ADOParameter prmID = new ADOParameter("AuthID",

ADODataType.VarChar, 11);

 

prmID.Value = "111-11-1111";

 

cmd.SelectCommand.Parameters.Add(prmID);

 

ADODataReader dr;

cmd.Execute (out dr);

SQLCommand cmd = new SQLCommand("spGetAuthorByID", con);

cmd.CommandType = CommandType.StoredProcedure;

 

SQLParameter prmID = new SQLParameter("@AuthID",

SQLDataType.VarChar,11);

 

prmID.Value = "111-11-1111"

cmd.SelectCommand.Parameters.Add(prmID);

SQLDataReader dr;

cmd.Execute(out dr);

阅读更多
个人分类: aspdotnet
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭