user1596298
user1596298

Reputation: 1

Retrieving multiple tables using a stored procedure in C#.net

How can I create a stored procedure that can SELECT FROM several tables and display the result in a HTML table? I did that by using only one table and used in ASP.NET using C#.

I used grid view, but it successed with only one table. I could have used a stored procedure that use only one table. I also used DataSource, but it worked with only one table.

Upvotes: 0

Views: 1517

Answers (2)

XN16
XN16

Reputation: 5869

You can return multiple tables from a stored procedure. One for each SELECT statement, then you fill a dataSet from the dataAdapter. Each SELECT statement's data will be in a seperate table within the dataSet.

I hope thats what you meant!

Upvotes: 1

Icarus
Icarus

Reputation: 63956

That would be something like this:

CREATE PROCEDURE MyProc 
as
BEGIN

  SELECT a.columna, b.columnb, c.columnc 
  from table a join table b on a.id=b.id
  join table c on c.id=a.id

END

Now your markup:

<asp:gridview id="grid" runat="server" DataSource="SqlDataSource1" .../>

<asp:SqlDataSource id="SqlDataSource1" SelectCommand="MyProc" 
SelectCommandType="StoredProcedure"  ConnectionString="<%$ ConnectionStrings:MyConnectionString%>" 

That's it.

Upvotes: 3

Related Questions