We use stored procedures for each query in the database. It seems unbelievably un <DRY:
- Create a table
- Create SP SP for this table
- Design code (preferably a class) to populate parameters and run CRUD SP
If we add one column or change the data type, we must edit the table, several SPs and several functions in the class in .NET.
What are some tips for reducing duplication?
UPDATE:
Combined with the Vinko idea, I found this . Here is some code (in C #) that I came up with for those who need it:
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["MySQLConnString"].ConnectionString);
SqlCommand comm = new SqlCommand("NameOfStoredProcedure", conn);
comm.CommandType = CommandType.StoredProcedure;
conn.Open();
SqlCommandBuilder.DeriveParameters(comm);
conn.Close();
foreach (SqlParameter param in comm.Parameters)
{ }
source
share