1

重複の可能性:
JavaScript で ADO を使用するステートメントの影響を受ける行数を取得するにはどうすればよいですか?

MS-SQL7.0、ASP(Jscript付き)を使用しており、クエリや実行に問題はありません。しかし、影響を受けるレコード数を取得する際に問題が発生しました。こちらのソースを参考に

http://support.microsoft.com/kb/195048

これが私たちのソースコードです

    var query = "...";
    this.db = Server.CreateObject("ADODB.Connection");
    this.db.Open(this.connectionString);
    this.db.Execute(query, this.rowCount);
    Response.Write(this.rowCount);

    or

    var query = "...";
    this.db = Server.CreateObject("ADODB.Connection");
    this.cmd  = Server.CreateObject("ADODB.Command");
    this.cmd.ActiveConnection = this.db;
    this.cmd.CommandText = query;
    this.cmd.Execute(this.rowCount);
    Response.Write(this.rowCount);

しかし、このコードは機能せずrowCount、初期値 (0) に設定されています。javascriptのプリミティブ型は常に値渡しだからだと思います。

4

2 に答える 2

1

過去に、そのような場合に2つの方法を試しました(同意しますが、少し引っかき傷があります.)。

1.言語の混合

<%@Language=JScript%>
<%
// 
// ..
this.query = "..."; // required
this.rowCount = 0; // required

ExecCommand(this);

//..
this.db.Close();
//..
%>
<script language="vbscript" runat="server">
Sub ExecCommand(obj)
    Dim intAffectedRows
    obj.db.Execute obj.query, intAffectedRows
    obj.rowCount = intAffectedRows 'assign rowCount
End Sub
</script>

2. RDBMS 機能が役立つ場合があります。(あなたはこれをしました)

<%@Language=JScript%>
<%
// 
// ..
var query = "...";
//..
this.db.Execute(query);
this.rowCount = this.db.Execute("Select @@ROWCOUNT").Fields.Item(0).Value;
//..
this.db.Close();
//..
%>
于 2012-02-20T07:22:41.830 に答える
-1

ActiveX データ オブジェクト (ADO) コマンド オブジェクトの Execute メソッドは、SQL UPDATE コマンドによって影響を受けるレコードの数を取得するために使用できる整数値を参照渡しします。

#DEFINE adModeReadWrite 3
#DEFINE adCmdText 1

oConnection = CREATEOBJECT("ADODB.Connection")
oCommand = CREATEOBJECT("ADODB.Command")

lcConnString = "DRIVER={SQL Server};" + ;
   "SERVER=YourServerName;" + ;
   "DATABASE=pubs"

lcUID = "YourUserID"
lcPWD = "YourPassword"

oConnection.ATTRIBUTES = adModeReadWrite
oConnection.OPEN(lcConnString, lcUID, lcPWD )

* Use the command object to perform an UPDATE
* and return the count of affected records.
strSQL = "UPDATE roysched SET royalty = royalty * 1.5"
liRecordsAffected = 0
WITH oCommand
   .CommandType = adCmdText
   .ActiveConnection = oConnection
   .CommandText = strSQL
   .Execute(@liRecordsAffected)
ENDWITH
=MESSAGEBOX("Records affected: " + LTRIM(STR(liRecordsAffected)))

* Set the royalty column back to its previous value.
strSQL = "UPDATE roysched SET royalty = royalty / 1.5"
liRecordsAffected = 0
WITH oCommand
   .CommandType = adCmdText
   .ActiveConnection = oConnection
   .CommandText = strSQL
   .Execute(@liRecordsAffected)
ENDWITH


=MESSAGEBOX("Records affected: " + LTRIM(STR(liRecordsAffected)))

http://support.microsoft.com/kb/195048

于 2012-02-20T04:28:18.597 に答える