Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Index was outside the bounds of the array. With linq query...

Reply
Thread Tools

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

 
 
Seb
Guest
Posts: n/a
 
      05-16-2008
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
HELP: strange behaviour when visiting the ASP website the 2nd time: "Index was outside the bounds of the array. " ton ASP .Net 4 12-17-2010 12:12 PM
help with pix inside->outside + dmz->outside + inside->outside->dmz Jack Cisco 0 09-19-2007 01:57 AM
Index was outside the bounds of the array Cammie Watson ASP .Net Web Services 1 12-01-2005 03:02 AM
Index was outside the bounds of the array =?Utf-8?B?Q2FtbWllIFdhdHNvbg==?= ASP .Net 3 11-28-2005 05:53 PM
Intermittent IndexOutOfRangeException: Index was outside the bounds of the array scotthutchinson@usa.net ASP .Net 0 04-10-2005 07:44 PM



Advertisments