Answer the question
In order to leave comments, you need to log in
How to get 2 tables in a stored procedure in SQL Server?
This works great when one result is:
using (var comm = new SqlCommand("dbo.GetProfile", conn))
{
comm.CommandType = CommandType.StoredProcedure;
comm.Parameters.Add(new SqlParameter("@uid", uid));
using (var reader = comm.ExecuteReader())
{
if (reader.Read())
{
Response.Write(reader["id"]);
Response.Write(reader["level"]);
}
}
}
ALTER PROCEDURE [dbo].[GetProfile]
@uid int
AS
BEGIN
SET NOCOUNT ON;
SELECT TOP 1 * FROM dbo.users where [email protected];
SELECT * FROM locations;
END
Answer the question
In order to leave comments, you need to log in
...
if (reader.Read())
{
Response.Write(reader["id"]);
Response.Write(reader["level"]);
}
var ok = reader.NextResult(); // <---
if( !ok ) return;
if (reader.Read())
{
Response.Write(reader["lid"]);
Response.Write(reader["sublid"]);
}
...
What is the purpose of using a stored procedure just to retrieve data? I understand that you would make requests for modification with the addition of logic in order to do all this on the database side, but why fetch? If there are specific reasons, indicate, and we will think about how best to do it.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question