Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Making A C# Routine Generic
Message
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Title:
Making A C# Routine Generic
Miscellaneous
Thread ID:
01245075
Message ID:
01245075
Views:
64
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
Next
Reply
Map
View

Click here to load this message in the networking platform