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> /// Summary description for WS. /// </summary> public class WS : System.Web.Services.WebService { public WS() { //CODEGEN: This call is required by the ASP+ Web Services Designer InitializeComponent(); } /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { } /// <summary> /// Clean up any resources being used. /// </summary> 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;