
Эксперт
  
Профиль
Группа: Завсегдатай
Сообщений: 1278
Регистрация: 14.1.2006
Где: г.Москва
Репутация: 3 Всего: 7
|
В клиенте есть две функции, одна вызывает в цикле хранимку выполняющую INSERT, работает корректно. И почти такая же функция вызывает почти такую же хранимку только выполняющую UPDATE, но работает некорректно. | Код | private void InsertWeekControl(KeyValuePair<string, ControlPlan> discipline) { for (byte j = 0; j < dgvWeekPlan.Columns.Count; j++) { ProcInvoke.ExecuteQuery("InsertWeekControl", QueryType.ExecuteNonQuery, CommandType.StoredProcedure, new ProcParams("@term", SqlDbType.TinyInt, 0, byte.Parse(cbTerms.Text[0].ToString()), ParameterDirection.Input), new ProcParams("@year", SqlDbType.Int, 0, int.Parse(udYear.Value.ToString()), ParameterDirection.Input), new ProcParams("@specialitySypher", SqlDbType.VarChar, 50, GetSpecialitySypher(), ParameterDirection.Input), new ProcParams("@disciplineSypher", SqlDbType.VarChar, 50, discipline.Key, ParameterDirection.Input), new ProcParams("@group", SqlDbType.VarChar, 50, this.chosenGroup, ParameterDirection.Input), new ProcParams("@week", SqlDbType.TinyInt, 0, j + 1, ParameterDirection.Input), new ProcParams("@controlType", SqlDbType.VarChar, 50, discipline.Value.WeekControl[j], ParameterDirection.Input)); } } private void UpdateWeekControl(KeyValuePair<string, ControlPlan> discipline) { for (byte j = 0; j < dgvWeekPlan.Columns.Count; j++) { //string all = string.Format("Term:{0};Year:{1};Spec:{2};Discipl:{3};Group:{4};Week:{5};type:{6}", // cbTerms.Text[0].ToString(), udYear.Value.ToString(), GetSpecialitySypher(), discipline.Key, // chosenGroup, j + 1, discipline.Value.WeekControl[j]); //MessageBox.Show(all, "UpdateDebug"); ProcInvoke.ExecuteQuery("UpdateWeekControl", QueryType.ExecuteNonQuery, CommandType.StoredProcedure, new ProcParams("@term", SqlDbType.TinyInt, 0, byte.Parse(cbTerms.Text[0].ToString()), ParameterDirection.Input), new ProcParams("@year", SqlDbType.Int, 0, int.Parse(udYear.Value.ToString()), ParameterDirection.Input), new ProcParams("@specialitySypher", SqlDbType.VarChar, 50, GetSpecialitySypher(), ParameterDirection.Input), new ProcParams("@disciplineSypher", SqlDbType.VarChar, 50, discipline.Key, ParameterDirection.Input), new ProcParams("@group", SqlDbType.VarChar, 50, this.chosenGroup, ParameterDirection.Input), new ProcParams("@week", SqlDbType.TinyInt, 0, j + 1, ParameterDirection.Input), new ProcParams("@controlType", SqlDbType.VarChar, 50, discipline.Value.WeekControl[j], ParameterDirection.Input)); } }
|
В столбы week и controlType в БД при операции UPDATE вставляются (по всем строкам) только последнее значение из discipline. Цикл по сути идёт от 1 до 18. Но после Update cтолбец week по всем строкам содержит число 18... | Код | ALTER PROCEDURE [dbo].[UpdateWeekControl] @term tinyint, @year int, @specialitySypher varchar(50), @disciplineSypher varchar(50), @group varchar(50), @week tinyint, @controlType varchar(50) AS BEGIN SET NOCOUNT ON;
UPDATE studying_graphics_weekControl SET [week]=@week, controlType=@controlType WHERE term=@term and [year]=@year and specialitySypher=@specialitySypher and disciplineSypher=@disciplineSypher and [group]=@group END
|
--------------------
Меня зовут Себастьян Парейра, торговец чёрным деревом.
|