Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1218
  • Last Modified:

Example webservice with ASP.NET 2.0 calling sql stored procedure

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
rss2
Asked:
rss2
  • 3
  • 3
1 Solution
 
GuitarRichCommented:
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
 
rss2Author Commented:
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
 
GuitarRichCommented:
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
Put Machine Learning to Work--Protect Your Clients

Machine learning means Smarter Cybersecurity™ Solutions.
As technology continues to advance, managing and analyzing massive data sets just can’t be accomplished by humans alone. It requires huge amounts of memory and storage, as well as high-speed processing of the cloud.

 
rss2Author Commented:
I've attached my code. When I run this, I get Service2ns is undefined.

Please help? :(
0
 
rss2Author Commented:
Attaching code again..just take the extension "txt" off the end of each file in order to open them up.
Service2.zip
0
 
GuitarRichCommented:
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

Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now