473,382 Members | 1,369 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Javascript in ASP I need a way of returning SQL message.

Dear Readers.

Using Javascript in ASP I need a way of returning through ADO
(connection or recordset) the message returned via SQL when I run a
query that UPDATES, DELETES or an SP that returns a message.

So I basically when the below code gets executed I need a way of
returning the message if it's there and if not nothing.

a)
var conn = Server.CreateObject("ADODB.Connection")
conn.Open(connStr)
conn.Execute("UPDATE shoe SET size = 12"); /*returns (12 row(s)
affected)*/
conn.Close
conn = null

b)
var conn = Server.CreateObject("ADODB.Connection")
conn.Open(connStr)
conn.Execute("EXEC usp_bob"); /*SP returns Couldn't find bob or
nothing*/
conn.Close
conn = null

It's being used in a generic function, so no case specific code.
Any help or link really appreciated.

Thanks folks!
Jul 19 '05 #1
2 1462
Instead of this:
conn.Execute("UPDATE shoe SET size = 12"); /*returns (12 row(s)
affected)*/


Try this:

var rs = conn.Execute("SET NOCOUNT ON; UPDATE shoe SET size = 12; SELECT
@@ROWCOUNT");
Response.Write(rs(0) + ' row(s) affected.');

You might also consider doing this in a stored procedure. Ad hoc sql is
generally not recommended.

--
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/
Jul 19 '05 #2
Aaron.

Thanks for your reply, but it wasn't exactly what I wanted.
I have a function called fireSQLXML(query) which in a nutshell runs a
query passed as a string from 100's of locations through out the code.
The function has some code to handle SELECT queries, and now some more
code that concatenates ‘SET NOCOUNT ON; SELECT @@ROWCOUNT' to DELETE &
UPDATE. But what I really need to get is any message returned by the
execution of a SP or some other query that isn't DELETE,UPDATE or
SELECT.

Some SP's might have a message, some don't, so I need a way of finding
out if the query returned a message or not.

In VB i usually do this with the conn.errors but I can't get this to
work correctly in JS using try/catch with conn.errors.

Thanks again for your help.

"Aaron Bertrand - MVP" <aa***@TRASHaspfaq.com> wrote in message news:<u9**************@TK2MSFTNGP11.phx.gbl>...
Instead of this:
conn.Execute("UPDATE shoe SET size = 12"); /*returns (12 row(s)
affected)*/


Try this:

var rs = conn.Execute("SET NOCOUNT ON; UPDATE shoe SET size = 12; SELECT
@@ROWCOUNT");
Response.Write(rs(0) + ' row(s) affected.');

You might also consider doing this in a stored procedure. Ad hoc sql is
generally not recommended.

Jul 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: JohnS | last post by:
Hi, A lot of functions (classes) in my JavaScript app are singletons. So, I have been exploring ways making JavaScript functions singletons. I thought I'ld run one idea past you all and get some...
2
by: Dean | last post by:
Hi I've got a question relating to using Javascript on an Intranet. I have a directory with a list of files in the format week36.xls, week37.xls and I want to write a script that will scan...
13
by: Kai Grossjohann | last post by:
It seems that Ctrl-N in Mozilla opens a new empty browser window. That's fine, I don't need to do anything about it. But Ctrl-N in IE appears to clone the current window. Is there a way to...
5
by: Sue | last post by:
After finishing up my first quarter JavaScript on 12/12/03, I decided to improve character checking on my project. In my project I only had to do very basic validation. Therefore, I only had one...
2
by: http://ray1.net/ | last post by:
Dear Readers. Using Javascript in ASP I need a way of returning through ADO (connection or recordset) the message returned via SQL when I run a query that UPDATES, DELETES or an SP that returns...
4
by: Roger Redford | last post by:
Dear Experts, I'm attempting to marry a system to an Oracle 817 datbase. Oracle is my specialty, the back end mainly, so I don't know much about java or javascript. The system uses javascript...
27
by: C Gillespie | last post by:
Dear All, Hopefully I have a simple problem. Basically, I just want to alter some text with JS. Here is some of my test code: <snip> <script type="text/javascript"> var tmp='a';
3
by: Shapper | last post by:
Hello, I am working on an ASP.NET/VB web site. I have several links including menu links. Considerer a want to load a page named page.aspx. I can do it using javascript. Or using this code:...
5
by: srini.venkatesan | last post by:
I am trying to call a javascript from Datagrid which is using OnUpdatecommand, I dont see update being invoked, what am I missing, Is it the right way to call. I have just cut and pasted only the...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.