/ Published in: SQL
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
######### 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 } }