|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
大家可以自己去看一看.可以说看得想呕吐.以前有次下了个动网来看.里面连基本内置函数的保护措施(函数没防御性)都没有.难怪经常补这个补那个了.可能现在.NET版会好点吧ADO2.6vs.theADO.NET
在本例中我们必要IIS5情况、VisualStudio.NETBETA1、另有SQLSERVER中的Northwind数据库
在.NET中,坚持了对新近COM及基于COM手艺的优秀撑持,在本例中供应了两种办法:GetCustomersOld()利用了ADO2.6;GetCustomersNew()利用ADO.NET,能够对照。
namespacePROINFO.WebService.Data
{
usingSystem;
usingSystem.Collections;
usingSystem.Configuration;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Data.SQL;
usingSystem.Diagnostics;
usingSystem.Web;
usingSystem.Web.Services;
///<summary>
///SummarydescriptionforWS.
///</summary>
publicclassWS:System.Web.Services.WebService
{
publicWS()
{
//CODEGEN:ThiscallisrequiredbytheASP+WebServicesDesigner
InitializeComponent();
}
///<summary>
///RequiredmethodforDesignersupport-donotmodify
///thecontentsofthismethodwiththecodeeditor.
///</summary>
privatevoidInitializeComponent()
{
}
///<summary>
///Cleanupanyresourcesbeingused.
///</summary>
publicoverridevoidDispose()
{
}
//Herestartstheexamplecode
publicstructsCustomers
{
publicStringsCustomerID;
publicStringsCompanyName;
publicStringsContactName;
publicStringsContactTitle;
publicStringsAddress;
publicStringsCity;
publicStringsRegion;
publicStringsPostalCode;
publicStringsCountry;
publicStringsPhone;
publicStringsFax;
}
[WebMethod(Description="ADO2.6WebMethodExample")]
publicsCustomers[]GetCustomersOld()
{
ADODB.Connectioncn=newADODB.Connection();
ADODB.Recordsetrs=newADODB.Recordset();
StringstrSQL;
intintRC;
intintCnt;
strSQL="SELECT*FROMCustomers";
cn.Open("Provider=SQLOLEDB;DataSource=SERVER;InitialCatalog=Northwind;","sa",null,0);
rs.Open(strSQL,cn,ADODB.CursorTypeEnum.adOpenStatic,ADODB.LockTypeEnum.adLockReadOnly,0);
intRC=rs.RecordCount;
if(intRC<1)
{
returnnull;
}
sCustomers[]c=newsCustomers[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++;
}
returnc;
}
[WebMethod(Description="ADO.NETWebMethodExample")]
publicDataSetGetCustomersNew()
{
DataSetds=newDataSet();
SQLConnectioncn=newSQLConnection("localhost","sa","","Northwind");
cn.Open();
SQLDataSetCommandcm=newSQLDataSetCommand("SELECT*FROMCustomers",cn);
cm.FillDataSet(ds,"Customers");
returnds;
}
}
}减少客户内IT专业人才缺乏带来的影响。ASP的客户员工利用浏览器进入相关的应用软件,简单易用,无需专业技术支持。 |
|