Comment exécuter une procédure stockée avec un paramètre nullable dans C#?.net: Comment exécuter une procédure stockée avec un paramètre nullable dans C#?
EDIT:
En fait, je l'ai écrit ci-dessous le code. Comme vous pouvez le voir, le paramètre status est un type de valeur Nullable. Est-ce correct? ou pas?
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;
}
}
Merci
Nous avons besoin d'un peu plus de détails ici: quel serveur de base de données? –
@jeremy: bien, SQL Server – odiseh
Vous devriez aussi mettre un 'using()' autour de votre adaptateur de données. –