Solved

Example webservice with ASP.NET 2.0 calling sql stored procedure

Posted on 2009-05-19
6
1,214 Views
Last Modified: 2012-05-07
Hello Gurus,

I have asp.net 2.0 framework. Can you send me an example webserivce that gets data from a stored procedure in sql 2005 and puts it in a grid?

Banging my head against the wall on this, and can't make it work. Keep getting "webservice undefined".
0
Comment
Question by:rss2
[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
  • 3
  • 3
6 Comments
 
LVL 12

Expert Comment

by:GuitarRich
ID: 24419808
well a webservice wouldn't put the results into a grid - the webservice should return a serialized bit of data. So in the webservice code you could stick the stored procedure results into a datatable and return that from the webservice.
The calling code can then consume that webservice and load the resulting datatable into a grid.

	[WebMethod]
	public DataSet GetData()
	{
		SqlConnection conn = new SqlConnection(connectionString);
		SqlCommand command = new SqlCommand("Stored Procedure Name", conn);
 
		// Add any command parameters here:
		command.Parameters.AddWithValue("@name", "value");
 
		DataSet data = new DataSet();
		SqlDataAdapter da = new SqlDataAdapter(command);
		da.Fill(data);
 
		return data;
	}
 
// and to load into the grid
 
	private void LoadGrid()
	{
		WebService ws = new WebService();
		DataSet data = ws.GetData();
 
		dataGridView1.DataSource = data;
		dataGridView1.DataMember = "table1";
		dataGridView1.DataBind();
	}

Open in new window

0
 

Author Comment

by:rss2
ID: 24420417
I thought a webservice like GetData should have the following parameters:
[WebMethod]
        public static List<Claim> GetData(int startIndex, int maximumRows, string sortExpressions, List<GridFilterExpression> filterExpressions)
        {
?
0
 
LVL 12

Expert Comment

by:GuitarRich
ID: 24420456
it should have whatever parameters it needs - mine was just a simple example to show how it could be done. Normally a routine to get some data would include some kind of filtering with parameters - but not always.
0
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 

Author Comment

by:rss2
ID: 24420459
I've attached my code. When I run this, I get Service2ns is undefined.

Please help? :(
0
 

Author Comment

by:rss2
ID: 24420489
Attaching code again..just take the extension "txt" off the end of each file in order to open them up.
Service2.zip
0
 
LVL 12

Accepted Solution

by:
GuitarRich earned 500 total points
ID: 24421028
ok - I don't think all the code is there - the cs files for the master page & the default page are missing.
Are you getting the error on the line:

setInterval("Service2ns.Service2.GetData(updateGrid)", 1000);
in the pageLoad javascript routine? setInterval is expecting you to pass it another javascript function. You need either call the webservice from code behind.
Or from what it looks like you should change that line to:

setInterval("updateGrid()", 1000);
But I'm not sure how you would pass in the result each time.
0

Featured Post

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
asp web application 3 39
How to force output to ascii 2 37
How come this XML node is not read? 3 28
aspx ascx, c# 7 11
The task of choosing a web design company to build a website for your business should never be taken in a light manner. Provided the fact that your website will act as a representative to your business and will be responsible for imposing an online …
In order to have all security and back ups taken care of, WordPress users can sign up for services with WP Engine.
The purpose of this video is to demonstrate how to set up the WordPress backend so that each page automatically generates a Mailchimp signup form in the sidebar. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

749 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