Solved

How to Call Stored Procedure and Display Results JavaScript

Posted on 2011-09-10
4
433 Views
Last Modified: 2012-05-12
Hi

I Currently have a stored procedure in ms sql server 2008 which is call from a C# page and returns data into a gridview.

The procedure is named: GetPricesForProduct
and accepts 1 param which is pid this is the product id

so my currect page would call the proc like productdetail.aspx?pid=16612

this would return columns into a gridview
site      Blogcategory      Productname      price

and repeat the data for all rows.

I want to be able to display this data in other sites and would like to call it as a javascript include file.

So I am looking to find out how to call the stored procedure with the param ?pid=16612 and how to output the results into html table using javascript.



0
Comment
Question by:jasont09
  • 2
  • 2
4 Comments
 
LVL 82

Expert Comment

by:leakim971
ID: 36516549
what about something like :
<script type="text/javascript" language="javascript" src="http://www.yourdomain.com/path/to/your/services/Service1.svc/GetProduct?pid=16612"></script>
0
 

Author Comment

by:jasont09
ID: 36516980
Hi leakim971

Your example shows me how to call it on the page, but I really dont have a clue about javascript and was looking for some guidance on how to call the actual stored procedure in the db and return the results into a javascript file which can then be called from the page using something like your example

can you help me please?
0
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 36517791
How to call a stored procedure from a web page :
http://www.databasejournal.com/features/mssql/article.php/3589021/Executing-SQL-Stored-Procedures-from-inside-a-Web-Application-Part-1.htm

Create a web service for example with WCF :
http://vishalnayan.wordpress.com/2011/03/31/create-your-first-restful-service-with-wcf-3-5/

so this web service receive (GET method) the product ID and output a javascript code LIKE that :

document.write("<table>");
document.write("<tr>");
document.write("<td>12</td><td>666</td>");
document.write("<td>12</td><td>666</td>");
document.write("</tr>");

Placing this script in your body page, it will create the table on the fly for you
0
 

Author Closing Comment

by:jasont09
ID: 36521729
Thanks for your help.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now