S
Seb
DataClassesDataContext db = new DataClassesDataContext();
SimpleProgramsHasExercise sphe = new
SimpleProgramsHasExercise();
int exerciseId =
(int)ExercisesGridView.DataKeys[ExercisesGridView.SelectedIndex].Values["ExerciseId"];
int simpleProgramId = int.Parse(DropDownList1.SelectedValue);
//The following two lines give men an "Index was outside the bounds of
the array." exception when I submit the changes
sphe.ExerciseId = exerciseId;
sphe.SimpleProgramId = simpleProgramId;
//the follwing code works... but is it really nessecary to do two
additionally linq querys?
//var exerciseQuery = from exercise in db.Exercises
// where exercise.ExerciseId == exerciseId
// select exercise;
//var simpleProgramQuery = from simpleProgram in
db.SimplePrograms
// where simpleProgram.SimpleProgramId
== simpleProgramId
// select simpleProgram;
//sphe.SimpleProgram =
simpleProgramQuery.Single<SimpleProgram>();
//sphe.Exercise = exerciseQuery.Single<Exercise>();
db.SimpleProgramsHasExercises.InsertOnSubmit(sphe);
db.SubmitChanges();
best regards
SimpleProgramsHasExercise sphe = new
SimpleProgramsHasExercise();
int exerciseId =
(int)ExercisesGridView.DataKeys[ExercisesGridView.SelectedIndex].Values["ExerciseId"];
int simpleProgramId = int.Parse(DropDownList1.SelectedValue);
//The following two lines give men an "Index was outside the bounds of
the array." exception when I submit the changes
sphe.ExerciseId = exerciseId;
sphe.SimpleProgramId = simpleProgramId;
//the follwing code works... but is it really nessecary to do two
additionally linq querys?
//var exerciseQuery = from exercise in db.Exercises
// where exercise.ExerciseId == exerciseId
// select exercise;
//var simpleProgramQuery = from simpleProgram in
db.SimplePrograms
// where simpleProgram.SimpleProgramId
== simpleProgramId
// select simpleProgram;
//sphe.SimpleProgram =
simpleProgramQuery.Single<SimpleProgram>();
//sphe.Exercise = exerciseQuery.Single<Exercise>();
db.SimpleProgramsHasExercises.InsertOnSubmit(sphe);
db.SubmitChanges();
best regards