快精灵印艺坊 您身边的文印专家
广州名片 深圳名片 会员卡 贵宾卡 印刷 设计教程
产品展示 在线订购 会员中心 产品模板 设计指南 在线编辑
 首页 名片设计   CorelDRAW   Illustrator   AuotoCAD   Painter   其他软件   Photoshop   Fireworks   Flash  

 » 彩色名片
 » PVC卡
 » 彩色磁性卡
 » 彩页/画册
 » 个性印务
 » 彩色不干胶
 » 明信片
   » 明信片
   » 彩色书签
   » 门挂
 » 其他产品与服务
   » 创业锦囊
   » 办公用品
     » 信封、信纸
     » 便签纸、斜面纸砖
     » 无碳复印纸
   » 海报
   » 大篇幅印刷
     » KT板
     » 海报
     » 横幅

ADO 2.6 vs. the ADO.NET

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;

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;
}
}
}
返回类别: 教程
上一教程: ASP 3.0 新特色先睹为快(一)
下一教程: 关于ASP访问ACCESS数据的错误的探讨

您可以阅读与"ADO 2.6 vs. the ADO.NET"相关的教程:
· ADO.NET:使用ADO.NET连接文本文件
· 在VS.NET中编写Web应用程序(一)
· 在VS.NET中编写Web应用程序(三)
· ADO连接数据库字符串大全(VP,EXCEL,文本,SYBASE,.NET等)
· 关于VS.NET beta1安装问题
    微笑服务 优质保证 索取样品