473,769 Members | 3,232 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.CreateOb ject("ADODB.Con nection")
conn.Open(connS tr)
conn.Execute("U PDATE shoe SET size = 12"); /*returns (12 row(s)
affected)*/
conn.Close
conn = null

b)
var conn = Server.CreateOb ject("ADODB.Con nection")
conn.Open(connS tr)
conn.Execute("E XEC 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 1479
Instead of this:
conn.Execute("U PDATE shoe SET size = 12"); /*returns (12 row(s)
affected)*/


Try this:

var rs = conn.Execute("S ET 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(quer y) 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***@TRASHasp faq.com> wrote in message news:<u9******* *******@TK2MSFT NGP11.phx.gbl>. ..
Instead of this:
conn.Execute("U PDATE shoe SET size = 12"); /*returns (12 row(s)
affected)*/


Try this:

var rs = conn.Execute("S ET 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
8295
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 feed back. The usual method of making singletons is to have a static member that returns one instance of the class. But, JavaScript has no notion of static. The closest it has is prototype functions.
2
17641
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 all the files in the directory and select the one with the highest week number then display in the browser window. A brief search hasn't revealed any code to do this so I just want to know if it is possible and what the function names are that...
13
9459
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 intercept the key so that I can do stuff on the server side to make the new window behave correctly? (We have a JSP-based webapp which stores state in the session. Now if two windows access (and modify!) the same session, then madness will result....
5
2692
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 function to verify the name fields, age, email and gender. My question is: if I create a function for each field like the code below, what would be the best way to organize the functions and call them? Would I need one main function and place...
2
1422
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 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)
4
7251
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 to make ODBC calls to the db. The particular system I'm working with, will not work with an Oracle stored procedure I'm told. However, it
27
2278
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
2127
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: Sub loadPage(sender As Object, e As System.EventArgs, pageURL as String)
5
1719
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 part of the code. Thanks In the class file: public void DataGrid2_Edit(Object sender, DataGridCommandEventArgs e) { DataGrid2.EditItemIndex = (int)e.Item.ItemIndex; BindGrid();
0
9590
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9424
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10223
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9866
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8879
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7413
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5310
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3571
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.