·您的位置: 首页 » 资源教程 » 编程开发 » ASP » 面向对象的ASP编程之四-一些常用的函数

面向对象的ASP编程之四-一些常用的函数

类别: ASP教程  评论数:0 总得分:0
function RecordSetAsArray(rsADO,includeHeaderRow)
//把ado.recordset中的数据存放到一个数组里
//当includeHeaderRow为真时产生字段标题行,当为假时不产生
{
var rsArray = new Array;
var nFields = rsADO.Fields.Count;
if (nFields)
{
var n = 0;
if (includeHeaderRow)
{// include first row as header of field names
var rsRow = new Array(nFields);
for (var i=0; i < nFields; i++)
rsRow[i] = rsADO(i).name;
rsArray[n++] = rsRow;
}
if (!(rsADO.EOF&&rsADO.Bof))
rsADO.MoveFirst()
while (!rsADO.EOF)
{// add each record to array
rsRow = new Array(nFields);
for (var i=0; i < nFields; i++)
rsRow[i] = rsADO(i).value;
rsArray[n++] = rsRow;
rsADO.MoveNext();
}
}
return rsArray;
}

function RecordSetAsDSO(rsADO)
//把ado.recordset中的数据放到一个表格中,返回这个表格的html代码
{
var htmlDSO = \'\';
var nFields = rsADO.Fields.Count;
if (nFields)
{
var n = 0;
htmlDSO += \'<\' + \'table>n\';
while (!rsADO.EOF)
{// add each record to table
htmlDSO += \'<\' + \'tr>\';
for (var i=0; i < nFields; i++)
{
htmlDSO += \'<\' + \'td id=\' + rsADO(i).name + \'>\' + rsADO(i).value + \'<\' + \'/td>\';
}
htmlDSO += \'<\' + \'/tr>n\';
rsADO.MoveNext();
}
htmlDSO += \'<\' + \'/table>\';
}
return htmlDSO;
}

function RecordSetAsList(rsADO,field)
//把ado.recordset中的某个字段的数据放到数组中
{
var rsArray = new Array;
var nFields = rsADO.Fields.Count;
if (nFields)
{
var n = 0;
if (!(rsADO.EOF&&rsADO.Bof))
rsADO.MoveFirst()
while (!rsADO.EOF)
{// add each value of field into array
rsArray[n++] = rsADO(field).value;
rsADO.MoveNext();
}
}
return rsArray;
}

function RecordAsObject(rsADO,objectName)
//以对象的方式返回ado.recordset中的一条记录
{
if (typeof(objectName) == \'undefined\')
objectName = \'RSObject\';
var strObject = \'function \' + objectName + \'() { \';
var nFields = rsADO.Fields.Count;
if (!rsADO.EOF)
{
var value = new String;
var propName = new String;
for (var i=0; i < nFields; i++)
{
propName = rsADO(i).name;
var c0 = propName.charAt(0);
if ((propName.indexOf(\' \') == -1) && ((c0 >= \'A\' && c0 <= \'Z\') || (c0 >= \'a\' && c0 <= \'z\')))
{// exclude fields that are invalid variable names
value = rsADO(i).value;
if (isNaN(parseFloat(value)))
strObject += \'this.\' + propName + \' = "\' + value + \'"; \';
else
strObject += \'this.\' + propName + \' = \' + value + \'; \';
}
}
}
strObject += \'}\';
eval(strObject);
return eval(\'new \' + objectName);
}



function RecordSetAsArray(rsADO,includeHeaderRow)
//把ado.recordset中的数据存放到一个数组里
//当includeHeaderRow为真时产生字段标题行,当为假时不产生
{
var rsArray = new Array;
var nFields = rsADO.Fields.Count;
if (nFields)
{
var n = 0;
if (includeHeaderRow)
{// include first row as header of field names
var rsRow = new Array(nFields);
for (var i=0; i < nFields; i++)
rsRow[i] = rsADO(i).name;
rsArray[n++] = rsRow;
}
if (!(rsADO.EOF&&rsADO.Bof))
rsADO.MoveFirst()
while (!rsADO.EOF)
{// add each record to array
rsRow = new Array(nFields);
for (var i=0; i < nFields; i++)
rsRow[i] = rsADO(i).value;
rsArray[n++] = rsRow;
rsADO.MoveNext();
}
}
return rsArray;
}

function RecordSetAsDSO(rsADO)
//把ado.recordset中的数据放到一个表格中,返回这个表格的html代码
{
var htmlDSO = \'\';
var nFields = rsADO.Fields.Count;
if (nFields)
{
var n = 0;
htmlDSO += \'<\' + \'table>n\';
while (!rsADO.EOF)
{// add each record to table
htmlDSO += \'<\' + \'tr>\';
for (var i=0; i < nFields; i++)
{
htmlDSO += \'<\' + \'td id=\' + rsADO(i).name + \'>\' + rsADO(i).value + \'<\' + \'/td>\';
}
htmlDSO += \'<\' + \'/tr>n\';
rsADO.MoveNext();
}
htmlDSO += \'<\' + \'/table>\';
}
return htmlDSO;
}

function RecordSetAsList(rsADO,field)
//把ado.recordset中的某个字段的数据放到数组中
{
var rsArray = new Array;
var nFields = rsADO.Fields.Count;
if (nFields)
{
var n = 0;
if (!(rsADO.EOF&&rsADO.Bof))
rsADO.MoveFirst()
while (!rsADO.EOF)
{// add each value of field into array
rsArray[n++] = rsADO(field).value;
rsADO.MoveNext();
}
}
return rsArray;
}

function RecordAsObject(rsADO,objectName)
//以对象的方式返回ado.recordset中的一条记录
{
if (typeof(objectName) == \'undefined\')
objectName = \'RSObject\';
var strObject = \'function \' + objectName + \'() { \';
var nFields = rsADO.Fields.Count;
if (!rsADO.EOF)
{
var value = new String;
var propName = new String;
for (var i=0; i < nFields; i++)
{
propName = rsADO(i).name;
var c0 = propName.charAt(0);
if ((propName.indexOf(\' \') == -1) && ((c0 >= \'A\' && c0 <= \'Z\') || (c0 >= \'a\' && c0 <= \'z\')))
{// exclude fields that are invalid variable names
value = rsADO(i).value;
if (isNaN(parseFloat(value)))
strObject += \'this.\' + propName + \' = "\' + value + \'"; \';
else
strObject += \'this.\' + propName + \' = \' + value + \'; \';
}
}
}
strObject += \'}\';
eval(strObject);
return eval(\'new \' + objectName);
}
注:此中的一些函数来源于MIcrosoft 的interdev中的Microsoft Scripting Library
-= 资 源 教 程 =-
文 章 搜 索
关键词:
类型:
范围:
纯粹空间 softpure.com
Copyright © 2006-2008 暖阳制作 版权所有
QQ: 15242663 (拒绝闲聊)  Email: faisun@sina.com
 纯粹空间 - 韩国酷站|酷站欣赏|教程大全|资源下载|免费博客|美女壁纸|设计素材|技术论坛   Valid XHTML 1.0 Transitional
百度搜索 谷歌搜索 Alexa搜索 | 粤ICP备19116064号-1