论坛交流
首页办公自动化| 网页制作| 平面设计| 动画制作| 数据库开发| 程序设计| 全部视频教程
应用视频: Windows | Word2007 | Excel2007 | PowerPoint2007 | Dreamweaver 8 | Fireworks 8 | Flash 8 | Photoshop cs | CorelDraw 12
编程视频: C语言视频教程 | HTML | Div+Css布局 | Javascript | Access数据库 | Asp | Sql Server数据库Asp.net  | Flash AS
当前位置 > 文字教程 > asp教程
Tag:入门,文摘,实例,技巧,iis,表单,对象,上传,数据库,记录集,session,cookies,存储过程,注入,分页,安全,优化,xmlhttp,fso,jmail,application,防盗链,stream,组件,md5,乱码,缓存,加密,验证码,算法,ubb,正则表达式,水印,,日志,压缩,url重写,控件,函数,破解,触发器,socket,ADO,初学,聊天室,留言本,视频教程

ADO 2.6 vs. the ADO.NET

文章类别:asp | 发表日期:2008-10-5 20:16:39

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;
}
}
}
上一篇:{应用}jsp强于asp,但不是asp.net 人气:4633
下一篇:{应用}用VB构建Internet的应用 人气:3612
视频教程列表
文章教程搜索
 
Asp推荐教程
Asp热门教程
看全部视频教程
购买方式/价格
购买视频教程: 咨询客服
tel:15972130058