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

Discussion in 'ASP .Net' started by Seb, May 16, 2008.

  1. Seb

    Seb Guest

    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
    Seb, May 16, 2008
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    3,171
  2. =?Utf-8?B?Q2FtbWllIFdhdHNvbg==?=

    Index was outside the bounds of the array

    =?Utf-8?B?Q2FtbWllIFdhdHNvbg==?=, Nov 28, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    9,736
    Patrice
    Nov 28, 2005
  3. Replies:
    10
    Views:
    545
    Mark McIntyre
    Apr 12, 2006
  4. ton
    Replies:
    4
    Views:
    1,026
  5. Cammie Watson

    Index was outside the bounds of the array

    Cammie Watson, Nov 25, 2005, in forum: ASP .Net Web Services
    Replies:
    1
    Views:
    173
Loading...

Share This Page