Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to Call Stored Procedure and Display Results JavaScript

Posted on 2011-09-10
4
Medium Priority
?
457 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 2000 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
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…
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…

715 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