Index was outside the bounds of the array. With linq query...

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,710
Latest member
bernietqt

Latest Threads

Top