Solved

How to Call Stored Procedure and Display Results JavaScript

Posted on 2011-09-10
4
437 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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to hide the rows in Table when the value is empty ? 4 40
Html5 Index on a table 7 26
where is team.js? 3 25
Checkout Page Input Field not aligned 1 23
In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
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…

773 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