J'essaie d'obtenir une valeur de sortie de la base de données via ADO.net. Il y a un code client:
using (var connection = new SqlConnection(ConnectionString))
{
connection.Open();
SqlCommand command = new SqlCommand("pDoSomethingParamsRes", connection);
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add("@i", 1);
var outParam = new SqlParameter("@out", SqlDbType.VarChar);
outParam.Direction = ParameterDirection.Output;
command.Parameters.Add(outParam);
command.ExecuteNonQuery();
Console.WriteLine(command.Parameters["@out"].Value.ToString());
}
Quand j'exécute ceci, j'obtiens l'exception suivante:
the Size property has an invalid size of 0
Selon le manuel SqlParameter.Size Property, je pourrais omettre la taille. Pourquoi ai-je cette exception? Comment le faire fonctionner sans passer de taille?
Merci de votre aide!