I’m working with VS 2010 Net Framework 3.5 and MySQL 5.1, with C#
Basically I have some parameters with different types (int, string, boolean, etc) and I need to send them to a MySQL parameter as input vars.
The last layer of my app is doing this:
public Boolean ExecuteProcedure(string ProcedureName, List<SqlParameter> ParameterCollection) {
Command.CommandType = CommandType.StoredProcedure;
Command.CommandText = ProcedureName;
Command.Parameters.AddRange(ParameterCollection.ToArray<SqlParameter>());
Command.ExecuteNonQuery();
(... etc etc)
So basically I need to convert on previous layers all my data into a List of SQL Parameters.
My questions are:
- This is a good idea? Maybe I sent another kind of object to the
ExecuteProcedure function? - Which is the better way to convert my vars of different kind into SQLParameter?
- Which limitations of use this kind of programming could be?
UPDATE:
My question is related to the communication between the layers. For example, the previous layer can be…
List<SqlParameter> INParameters = new List<SqlParameter>();
INParameters.Add(new SqlParameter("error_code",error_code));
INParameters.Add(new SqlParameter("error_description",error_description));
SysDB.ExecuteProcedure("sys_log_insert_error", INParameters);
Is this a good way to do this?
Thanks and kind regards,
If you don’t want the top layer to know anything about SQL or SQLParameters, you can pass something more generic like
KeyValuePair(http://msdn.microsoft.com/en-us/library/5tbh8a42.aspx)I would change
ExecuteProcedureto something like this >>public Boolean ExecuteProcedure(string ProcedureName, params KeyValuePair<String, Object>[] ParameterCollection) { ... }You may also have some helper method that takes in the
KeyValuePairs which you call inExecuteProcedureto transform them intoSQLParameterobjects that you can then use in your query..I think you get the point..