How to execute a stored procedure with a nullable parameter in c#?
EDIT:
Actually, I've written below code. As you can see, status parameter is a nullable value type. Is it correct? or not?
public void LoadAll(DataTable tb, int? status=null)
{
try
{
using (SqlConnection connection = new SqlConnection())
{
connection.ConnectionString = this.connectionString;
using (SqlCommand command = connection.CreateCommand())
{
command.CommandType = CommandType.StoredProcedure;
command.CommandText = "USP_OrganizationChartSelect";
SqlCommandBuilder.DeriveParameters(command);
command.Parameters["@Status"].Value = status.HasValue ? status : null;
if (connection.State != ConnectionState.Open)
connection.Open();
SqlDataAdapter adapter = new SqlDataAdapter(command);
tb.Clear();
adapter.Fill(tb);
adapter.Dispose();
adapter = null;
}
}
}
catch (Exception ex)
{
throw ex;
}
}
Thanks