JScript 模拟 ADO.NET 基本对象

来源:互联网 发布:杭州淘宝美工师培训 编辑:程序博客网 时间:2024/06/05 17:20

<%@ Language="JScript" CODEPAGE = "936" %>
<!-- METADATA TYPE="TypeLib" UUID="00000200-0000-0010-8000-00AA006D2EA4" -->
<%
/*
ADO.NET Module For ASP

Error:
err.name
err.message
err.description

*/
// OLEDBConnection Class
function OLEDBConnection(strConnection)
{

  this.ConnectionString = strConnection;
  this.Connection = Server.CreateObject("ADODB.Connection");
  this.Connection.ConnectionString = this.ConnectionString;

  this.Open = function()
  {
    try {
      this.Connection.ConnectionString = this.ConnectionString;
      this.Connection.Open();
    }   catch(err) {
      err.name = "Connection Open Error"
      Debug(err);
    }
  }

  this.Close = function()
  {
    try {
      this.Connection.Close;
    } catch(err) {
      err.name = "Connection Close Error"
      Debug(err);
    }
  }

// return this.Connection;
}


// OLEDBCommand Class
function OLEDBCommand(strCommandText, objConnection)
{
  this.CommandText = strCommandText;
  this.Connection = objConnection;
  this.Command = Server.CreateObject("ADODB.Command");
  this.Command.CommandType = 8; // adCmdUnknown
  this.Command.CommandText = this.CommandText;

  this.ExecuteReader = function()
  {
    try {
      this.Command.CommandText = this.CommandText;
      this.Command.ActiveConnection = this.Connection.Connection;
      return this.Command.Execute;
    } catch(err) {
      err.name = "ExecuteReader Error"
      Debug(err);
    }
  }

  this.ExecuteNonQuery = function()
  {
    try {
      this.Command.ActiveConnection = this.Connection;
      this.Command.Execute;
    } catch(err) {
      err.name = "ExecuteNonQuery Error"
      Debug(err);
    }
  }
// prototype: Parameters
  this.Parameters = function(strParametersName,strParametersValue)
  {

    this.Parameters.Name = strParametersName;
    this.Parameters.Value = strParametersValue;
    if ((this.Parameters.Name) && (this.Parameters.Value)) {
      this.Command.Parameters(this.Parameters.Name) = this.Parameters.Value;
    }
  }
// prototype: AddParameters
  this.CreateParameters = function(strParametersName, intParametersType, intParametersDirection, intParametersSize, strParametersValue)
  {
    this.Parameters.Name = strParametersName;
    this.Parameters.Type = intParametersType;
    this.Parameters.Direction = intParametersDirection;
    this.Parameters.Size = intParametersSize;
    this.Parameters.Value = strParametersValue;
    this.Command.Parameters.Append(this.Command.CreateParameter(this.Parameters.Name, this.Parameters.Type, this.Parameters.Direction, this.Parameters.Size, this.Parameters.Value));
  }

  function Debug(err)
  {
    Response.Write (err.name);
    Response.Write ("<br>")
    Response.Write (err.description);
    Response.End
  }
//  return this.Command
}
%>

原创粉丝点击