Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 354 Vote(s) - 3.45 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Get affected count of rows from ADODB & ASP with JScript

#1
> **Possible Duplicate:**
> [How can I get the # of rows affected by a statement using ADO with JavaScript?](

[To see links please register here]

)

<!-- End of automatically inserted text -->

We're using MS-SQL7.0, ASP(with Jscript)
there isn't any problem in querying and executing.
But we faced an problem getting affected record count.
We refer to this source

[To see links please register here]


Here is our source code

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);

But this code don't work, `rowCount` are set to its initial value(0).
I think it because primitive type in javascript is always called by value.



[1]:

[To see links please register here]

Reply

#2
The Execute method of the ActiveX Data Objects (ADO) Command object passes by reference an integer value that you can use to retrieve the number of records affected by a SQL UPDATE command.


#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)))


[To see links please register here]

Reply

#3
<!-- language: lang-js -->
In the past I've tried two methods in such a case (I agree, a little bit scratchy.).<br />

**1. Mixing languages**

<%@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 features can be useful.** (you did this)

<%@Language=JScript%>
<%
//
// ..
var query = "...";
//..
this.db.Execute(query);
this.rowCount = this.db.Execute("Select @@ROWCOUNT").Fields.Item(0).Value;
//..
this.db.Close();
//..
%>
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through