您的位置:首页网页设计ASP文摘 → ADO 2.6 vs. the ADO.NET

ADO 2.6 vs. the ADO.NET

时间:2004/11/7 3:08:00来源:本站整理作者:蓝点我要评论(0)

ADO 2.6 vs. the ADO.NET

在本例中我们需要IIS5环境、Visual Studio.NET BETA1、还有SQL SERVER中的Northwind数据库

在.NET中,保持了对早先COM及基于COM技术的良好支持,在本例中提供了两种方法:GetCustomersOld() 使用了ADO2.6;GetCustomersNew() 使用ADO.NET,可以对比。



namespace PROINFO.WebService.Data

{

using System;

using System.Collections;

using System.Configuration;

using System.ComponentModel;

using System.Data;

using System.Data.SQL;

using System.Diagnostics;

using System.Web;

using System.Web.Services;

///

/// Summary description for WS.

///


public class WS : System.Web.Services.WebService

{

public WS()

{

//CODEGEN: This call is required by the ASP+ Web Services Designer

InitializeComponent();

}

///

/// Required method for Designer support - do not modify

/// the contents of this method with the code editor.

///


private void InitializeComponent()

{

}

///

/// Clean up any resources being used.

///


public override void Dispose()

{

}



// Here starts the example code

public struct sCustomers

{

public String sCustomerID;

public String sCompanyName;

public String sContactName;

public String sContactTitle;

public String sAddress;

public String sCity;

public String sRegion;

public String sPostalCode;

public String sCountry;

public String sPhone;

public String sFax;

}



[WebMethod(Description="ADO 2.6 WebMethod Example")]

public sCustomers[] GetCustomersOld()

{

ADODB.Connection cn = new ADODB.Connection();

ADODB.Recordset rs = new ADODB.Recordset();

String strSQL;

int intRC;

int intCnt;

strSQL = "SELECT * FROM Customers";

cn.Open("Provider=SQLOLEDB; Data Source=SERVER; Initial Catalog=Northwind;", "sa", null, 0);

rs.Open(strSQL, cn, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockReadOnly, 0);

intRC = rs.RecordCount;

if (intRC < 1)

{

return null;

}

sCustomers[] c = new sCustomers[intRC];

rs.MoveFirst();

intCnt = 0;



while (!rs.EOF)

{

c[intCnt].sCustomerID = rs.Fields["CustomerID"].Value.ToString();

c[intCnt].sCompanyName = rs.Fields["CompanyName"].Value.ToString();

c[intCnt].sContactName = rs.Fields["ContactName"].Value.ToString();

c[intCnt].sContactTitle = rs.Fields["ContactTitle"].Value.ToString();

c[intCnt].sAddress = rs.Fields["Address"].Value.ToString();

c[intCnt].sCity = rs.Fields["City"].Value.ToString();

c[intCnt].sRegion = rs.Fields["Region"].Value.ToString();

c[intCnt].sPostalCode = rs.Fields["PostalCode"].Value.ToString();

c[intCnt].sCountry = rs.Fields["Country"].Value.ToString();

c[intCnt].sPhone = rs.Fields["Phone"].Value.ToString();

c[intCnt].sFax = rs.Fields["Fax"].Value.ToString();

rs.MoveNext();

intCnt++;

}

return c;

}



[WebMethod(Description="ADO.NET WebMethod Example")]

public DataSet GetCustomersNew()

{

DataSet ds = new DataSet();

SQLConnection cn = new SQLConnection("localhost", "sa", "", "Northwind");

cn.Open();

SQLDataSetCommand cm = new SQLDataSetCommand("SELECT * FROM Customers", cn);

cm.FillDataSet(ds, "Customers");

return ds;

}

}

}

相关阅读 Windows错误代码大全 Windows错误代码查询激活windows有什么用Mac QQ和Windows QQ聊天记录怎么合并 Mac QQ和Windows QQ聊天记录Windows 10自动更新怎么关闭 如何关闭Windows 10自动更新windows 10 rs4快速预览版17017下载错误问题Win10秋季创意者更新16291更新了什么 win10 16291更新内容windows10秋季创意者更新时间 windows10秋季创意者更新内容kb3150513补丁更新了什么 Windows 10补丁kb3150513是什么

文章评论
发表评论

热门文章 没有查询到任何记录。

最新文章 没有查询到任何记录。 用不着妄自菲薄 对ASP和ASP程序员的一些话技术分析:.NET的优势与劣势代码大战:哪种语言会赢得开发的霸权?IIS 5.1和IIS 6.0一些显著的重要区别

人气排行 微软提供的功能强大的ASP-HTML转换工具.它将用ASP技术实现在WEB网页上浏览目录及文件从VB 6.0到VB.NET的转换2从VB 6.0到VB.NET的转换5IIS 5.1和IIS 6.0一些显著的重要区别从VB 6.0到VB.NET的转换1将.Net应用移植到Linux上来的Mono工程Serv-U :快速构建功能强大的FTP 服务器