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
????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
????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 += '\n';???
??while (!rsADO.EOF)
??{?// add each record to table
???htmlDSO += '';???
???for (var i=0; i
???{
????htmlDSO += '' + rsADO(i).value + '';
???}
???htmlDSO += '\n';???
???rsADO.MoveNext();
??}
??htmlDSO += '';???
?}
?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
??{
???propName = rsADO(i).name;
???var c0 = propName.charAt(0);
???if ((propName.indexOf(' ') == -1) && ((c0 = 'A' && c0 = 'a' && c0
???{?// 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
????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
????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 += '\n';???
??while (!rsADO.EOF)
??{?// add each record to table
???htmlDSO += '';???
???for (var i=0; i
???{
????htmlDSO += '' + rsADO(i).value + '';
???}
???htmlDSO += '\n';???
???rsADO.MoveNext();
??}
??htmlDSO += '';???
?}
?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
??{
???propName = rsADO(i).name;
???var c0 = propName.charAt(0);
???if ((propName.indexOf(' ') == -1) && ((c0 = 'A' && c0 = 'a' && c0
???{?// 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