Link to home
Start Free TrialLog in
Avatar of rss2
rss2

asked on

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".
Avatar of GuitarRich
GuitarRich
Flag of United Kingdom of Great Britain and Northern Ireland image

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

Avatar of rss2
rss2

ASKER

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)
        {
?
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.
Avatar of rss2

ASKER

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

Please help? :(
Avatar of rss2

ASKER

Attaching code again..just take the extension "txt" off the end of each file in order to open them up.
Service2.zip
ASKER CERTIFIED SOLUTION
Avatar of GuitarRich
GuitarRich
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial