Return to Snippet

Revision: 28078
at June 30, 2010 11:08 by vedgiee


Initial Code
######### SQL #########################################

CREATE PROCEDURE dbo.getTwoValues
(
	@param1 int
)

AS

SELECT returnval1, returnval2 FROM tblWhatever WHERE param1 = @param1

########## C# #########################################

string connString = ConnectionManager.ConnectionString["ConnString"].ToString();

using(SqlConnection conn = new SqlConnection(connString))
{
	SqlCommand getTwoValues = new SqlCommand("[getTwoValues]", conn);
	getTwoValues.CommandType = ...StoredProcedure;
	getTwoValues.Parameters.AddWithValue("@param1", 1);
	
	conn.Open();
	SqlDataReader reader = getTwoValues.ExecuteReader();
	
	// Repeat for all returned rows
	while(reader.Read())
	{
		string firstValue = reader.GetString(reader.GetOrdinal("returnval1"));
		int secondValue = reader.GetInt32(readder.GetOrdinal("returnval2"));
		
		// Do stuff with values
	}
}

Initial URL

                                

Initial Description

                                

Initial Title
Return Multiple Values Stored Procedure

Initial Tags
sql

Initial Language
SQL