473,401 Members | 2,146 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,401 software developers and data experts.

How to call a stored procedure in Javascript

112 100+
Hello there

I would like to know if I can call a stored procedure from java script function.. I have a hyperlink, which should allow user to insert or delete or edit a column in the database. can this be done?? i would like to put the functionality in the javascript function
my page is an asp page.......

thank you
May 17 '10 #1
3 7796
chathura86
227 100+
i dont think so, cuz as far as i know js cannot connect to a database
on the other hand even if you can since you have the connection string on the
js, anyone can see your usernames and passwords so i guess you should use
asp to do that stuff

Regards
May 18 '10 #2
acoder
16,027 Expert Mod 8TB
Although this is not possible with JavaScript, you can make an ASP page which calls the stored procedure and whatever result ensues, and then make a request to that page via Ajax.
May 19 '10 #3
Expand|Select|Wrap|Line Numbers
  1. public string[] CCNumLookup(string prefixText) 
  2.         {
  3.  
  4.             SqlConnection conn = new SqlConnection("connectionstring goes here");
  5.  
  6.             SqlCommand command = null;
  7.             command = new SqlCommand("You stored Procedure name here", conn);
  8.  
  9.             DataTable dt = new DataTable();
  10.             SqlDataAdapter adapter = null;
  11.  
  12.             try
  13.             {
  14.                 command.Parameters.Add("@prefixText", SqlDbType.NVarChar, 50).Value = prefixText + "%";
  15.                 adapter = new SqlDataAdapter(command);
  16.                 adapter.Fill(dt);
  17.             }
  18.             catch (Exception e)
  19.             {
  20.                 //handle exception
  21.             }
  22.             finally
  23.             {
  24.                 if (adapter != null)
  25.                 {
  26.                     adapter.Dispose();
  27.                 }
  28.  
  29.                 if (command != null)
  30.                 {
  31.                     command.Dispose();
  32.                 }
  33.  
  34.                 if (conn != null)
  35.                 {
  36.                     if (conn.State == ConnectionState.Open)
  37.                     {
  38.                         conn.Close();
  39.                     }
  40.                     conn = null;
  41.                 }
  42.  
  43.             }
  44.             string[] items = new string[dt.Rows.Count]; 
  45.             int i = 0;
  46.  
  47.             foreach (DataRow dr in dt.Rows) 
  48.             {
  49.  
  50.             items.SetValue(dr["cost_center"].ToString(), i);
  51.  
  52.             i++; 
  53.             }
  54.  
  55.             return items; 
  56.         }
Oct 26 '11 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: dw | last post by:
Hello all, I'm having a dickens of a time calling a stored procedure on a connection. Every time I do, it generates an error "Arguments are of the wrong type, are out of acceptable range, or are in...
0
by: HumanJHawkins | last post by:
"HumanJHawkins" <JHawkins@HumanitiesSoftware.Com> wrote in message news:i9nac.8030$Dv2.2242@newsread2.news.pas.earthlink.net... > (The SQL Group suggested I post this here... Sorry for the...
0
by: JN | last post by:
Hello, I'm having problem calling stored procedures from Visual FoxPro database. I got the following exception error: "System.Data.OleDb.OleDbException: Unrecognized command verb" It seems...
6
by: Scott McNair | last post by:
Hi all, I'm having problems calling a stored procedure from within my code. If I execute the SP manually from a Query Analyzer window it runs without a hitch, but it seems it doesn't even fire...
4
by: Jack | last post by:
Hi, I am trying to run an example code from a book. However I am getting the following error message: Number: -2147217900 Description: Syntax error or access violation Source: Microsoft OLE...
14
by: krishna1412 | last post by:
Currently i am working in a project of report generation in MS ACCESS. The tables are in sql server 2000. I have to write stored proc in ms access. Illustration: I am having a stored proc...
4
by: eighthman11 | last post by:
I'm calling a stored procedure on a sql server from an access application. I just need the stored procedure to run I do not need any data returned from the stored procedure to my Access...
2
by: =?Utf-8?B?YW5vb3A=?= | last post by:
Hello, I have a stored procedure named as usp_CheckLogin with two parameters as @usID, @Password also values of these parameters are to be extracted using Request.Form from the fields in...
3
by: yinzara | last post by:
I have the following trigger that calls a DB2 stored procedure: DROP TRIGGER GGWU.TRI_A_MULTI_PROP@ CREATE TRIGGER GGWU.TRI_A_MULTI_PROP AFTER INSERT ON GGWU.MULTIPLIER_PROPERTY REFERENCING ...
6
Soniad
by: Soniad | last post by:
Hello, I am excecuting a stored procedure in my ASP page , it has one out parameter (@confirm) . after executing the procedure i want to retreive this out parameter and assign it to variable...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...

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.