Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Making A C# Routine Generic
Message
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Titre:
Making A C# Routine Generic
Divers
Thread ID:
01245075
Message ID:
01245075
Vues:
66
I wrote a small method in C# that calls into SQL to validate a GUID. It takes a param and then
calls into SQL

How can I make this routine into a single piece of code that runs a stored proc? I would have to
pass the proc name and any params:
public static void test_guid()
{
    string sConnString = "Data Source = KMAROIS\\SQLEXPRESS;Initial Catalog=sc;Trusted_Connection=Yes;";
    string sValue = "A9DD08A4-94D8-4D93-BEC8-AE2ABA96AA0E";

    SqlConnection oConnection = new SqlConnection(sConnString);

    SqlCommand oCommand = new SqlCommand();
    oCommand.Connection = oConnection;
    oCommand.CommandText = "sp_IsValidUniqueId";
    oCommand.CommandType = CommandType.StoredProcedure;

    SqlParameter oUniqueId = new SqlParameter("@UniqueId", SqlDbType.VarChar, 36);
    SqlParameter oIsValid = new SqlParameter("@IsValid", SqlDbType.TinyInt);
    oIsValid.Direction = ParameterDirection.Output;

    oUniqueId.Value = sValue;
    oIsValid.Value = 0;

    oCommand.Parameters.Add(oUniqueId);
    oCommand.Parameters.Add(oIsValid);

    oConnection.Open();

    SqlDataReader oDataReader = oCommand.ExecuteReader(); 

}
Everything makes sense in someone's mind
public class SystemCrasher :ICrashable
In addition, an integer field is not for irrational people
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform