I have a schedule application in which users enter their time in / out for different days of the week. The form processes the input / output from each day, fills them as parameters into the stored procedure and adds them to the database. How could I do this most efficiently? I do not have access to the database, but only stored procedures.
This is clean code, I deleted some unnecessary codes.
SqlConnection conn = new SqlConnection(connString); conn.Open(); SqlCommand cmd = new SqlCommand("insertINOUT", conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add(new SqlParameter("@UserName", user)); for (int j = 0; j < weekDays.Length; j++) { cmd.Parameters.Add(new SqlParameter("@In", in)); cmd.Parameters.Add(new SqlParameter("@Out", out)); cmd.ExecuteReader(); } conn.Close();
The code works if there is only one day of entry / exit. If users fill out several days, I will get this error: The parameter "@In" was sent several times.
Thank you for your help.
source share