Solved

How to Call Stored Procedure and Display Results JavaScript

Posted on 2011-09-10
4
441 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…

756 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