This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static void OutputNoDefault(SqlCommand cmd) | |
{ | |
cmd.CommandType = CommandType.StoredProcedure; | |
cmd.CommandText = "usp_Output_No_Default"; | |
SqlParameter par = new SqlParameter("@param1", SqlDbType.VarChar); | |
par.Direction = ParameterDirection.Output; | |
par.Size = 50; | |
par.Value = null; | |
cmd.Parameters.Add(par); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static void NoInputWithDefault(SqlCommand cmd) | |
{ | |
cmd.CommandType = CommandType.StoredProcedure; | |
cmd.CommandText = "usp_Input_Has_Default"; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static void InputDbNullWithDefault(SqlCommand cmd) | |
{ | |
cmd.CommandType = CommandType.StoredProcedure; | |
cmd.CommandText = "usp_Input_Has_Default"; | |
SqlParameter par = new SqlParameter("@param1", SqlDbType.VarChar); | |
par.Direction = ParameterDirection.Input; | |
par.Value = DBNull.Value; | |
cmd.Parameters.Add(par); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static void InputNullWithDefault(SqlCommand cmd) | |
{ | |
cmd.CommandType = CommandType.StoredProcedure; | |
cmd.CommandText = "usp_Input_Has_Default"; | |
SqlParameter par = new SqlParameter("@param1", SqlDbType.VarChar); | |
par.Direction = ParameterDirection.Input; | |
par.Value = null; | |
cmd.Parameters.Add(par); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE PROCEDURE [dbo].[usp_Input_Has_Default] | |
@param1 varchar(50) = 'I''m a default value' | |
AS | |
SELECT @param1; | |
RETURN 0; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static void InputWithNoDefault_DBNullValue(SqlCommand cmd) | |
{ | |
cmd.CommandType = CommandType.StoredProcedure; | |
cmd.CommandText = "usp_Input_No_Default"; | |
SqlParameter par = new SqlParameter("@param1", SqlDbType.VarChar); | |
par.Direction = ParameterDirection.Input; | |
par.Value = DBNull.Value; | |
cmd.Parameters.Add(par); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static void InputWithNoDefault_NullValue(SqlCommand cmd) | |
{ | |
cmd.CommandType = CommandType.StoredProcedure; | |
cmd.CommandText = "usp_Input_No_Default"; | |
SqlParameter par = new SqlParameter("@param1", SqlDbType.VarChar); | |
par.Direction = ParameterDirection.Input; | |
par.Value = null; | |
cmd.Parameters.Add(par); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE PROCEDURE [dbo].[usp_Input_No_Default] | |
@param1 varchar(50) | |
AS | |
SELECT @param1; | |
RETURN 0; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static void InputWithNoDefault(SqlCommand cmd) | |
{ | |
cmd.CommandType = CommandType.StoredProcedure; | |
cmd.CommandText = "usp_Input_No_Default"; | |
SqlParameter par = new SqlParameter("@param1", SqlDbType.VarChar); | |
par.Direction = ParameterDirection.Input; | |
par.Value = "Foo"; | |
cmd.Parameters.Add(par); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static void Main(string[] args) | |
{ | |
SqlConnectionStringBuilder bldr = new SqlConnectionStringBuilder(); | |
bldr.DataSource = "(localdb)\\DEV"; | |
bldr.InitialCatalog = "DbParams"; | |
bldr.ApplicationName = "ParameterBehavior"; | |
bldr.IntegratedSecurity = true; | |
using (SqlConnection con = new SqlConnection(bldr.ConnectionString)) | |
using (SqlCommand cmd = con.CreateCommand()) |