473,669 Members | 2,458 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Exception: Index was outside the bounds of the array

Hi,

I'm dealing with a master-detail relationship. A datagrid bound to the
detail data. When navigating through the records (next record:
Me.BindingConte xt(mDv1).Positi on += 1), I notice a delay of about 2 sec's if
the detail datagrid is empty (no records to show for this master-record). The
delay happens only once per application run!! After exception debugging a
found that when this happens a "first chance exception of type
'System.IndexOu tOfRangeExcepti on' is thrown. Who knows how to deal with/solve
this situation?

Regards Coen
Nov 21 '05 #1
12 5026
Coen

Probably something as (roughly typed here)
\\\\
if mDV1.count - 2 > me.bindingconte xt(mDv1).Postit ion then
Me.BindingConte xt(mDv1).Positi on += 1)
end if
///
I hope this helps?

Cor
Nov 21 '05 #2
Hi Cor, thanks for your response.

Unfortunately this is not the case. The delay happens whenever the related
detail table has no related rows to show. This can happen at master row nr 5
of 100, or whatever... Any case the master table is not even near his last
record. The most important issue is that it always happens only once per
application-run, and only if the related detail table has for the current
master record no corresponding detail rows.

Again, any help is welcome.
Regards Coen.

"Cor Ligthert" wrote:
Coen

Probably something as (roughly typed here)
\\\\
if mDV1.count - 2 > me.bindingconte xt(mDv1).Postit ion then
Me.BindingConte xt(mDv1).Positi on += 1)
end if
///
I hope this helps?

Cor

Nov 21 '05 #3
Coen,

After that an exception is thrown the "same" next exception takes only some
milliseconds so you will probably not see that however it is probably much
more in your program.

From the information I have now I cannot see what it can be, however it
should than be somewhere in your related table in the way you describe it.

Cor
Nov 21 '05 #4
However I agree that there should than be an exception, when you did not as
some people do put an empty Try Catch block around it

Try
do something
Catch
End Try

What is of course the worsest thing in programming so I assume you did not
do that.

Cor
Nov 21 '05 #5
Cor,

I'm not using empty Try Catch blocks. But I have found the cause of this
exception. The exception only occurs when the related datagrid's READONLY
property is put to true. Navigating to the next (master) record without any
related detail records to show (in the datagrid), causes this
IndexOutOfRange Exception. Of course I can work around this like:

grdContacts.Rea dOnly = False
Me.BindingConte xt(mDv1).Positi on += 1
grdContacts.Rea dOnly = True

This works fine, I have tested this successfull. Still I'm supprised this
happens. I think, this was not necessary in VS2002+Framewor k 1.0. I could
check this next wednesday. I wonder if this is logic and necessary, I would
like your opinion of this.

Regards Coen

"Cor Ligthert" wrote:
However I agree that there should than be an exception, when you did not as
some people do put an empty Try Catch block around it

Try
do something
Catch
End Try

What is of course the worsest thing in programming so I assume you did not
do that.

Cor

Nov 21 '05 #6
Coen,

I tested this in a program I have, however I see in the related datagrid a
nice header with no rows.

This datagrid is with columnstyles by the way.

Cor
Nov 21 '05 #7
Cor, I suppose you turned on "catching the IndexOutOfRange Exception", via the
Debug menu, Exceptions, CLR exceptions, System,
System.IndexOut OfRangeExceptio n. --> Breaking into the debugger? Otherwise
you'll see only a two sec's delay (only once), but no execute interuption.

I downsized my project, also using a dataset without a dataview, but the
exception is still there, however the remaining code is very basic. I'll
paste it underneath, so maybe you can have a look at it? The form contains
four textboxes (bound to the master table), four navigation buttons, and one
datagrid (detail-rows). A connection is made to the Northwind database
(please modify the connectionstrin g).

Maybe you see a difference with your testcode?
Regards Coen

--------------------- Start Code: -------------------
Imports System
Imports System.Data
Imports System.Data.Sql Client

Public Class Form1
Inherits System.Windows. Forms.Form

Dim myConnection As SqlConnection
Dim mDs As New DataSet
Dim mDa1 As SqlDataAdapter
Dim mDa2 As SqlDataAdapter

Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load

myConnection = New
SqlConnection(" server=(local)\ INSTANCE01;Trus ted_Connection= yes;database=no rthwind")
mDa1 = New SqlDataAdapter( "SELECT * FROM Customers", myConnection)
mDa2 = New SqlDataAdapter( "SELECT * FROM orders", myConnection)

'Fill dataset
mDa1.Fill(mDs, "Customers" )
mDa2.Fill(mDs, "Orders")

'Define relation
mDs.Relations.A dd(New DataRelation( _
relationName:=" relCustomersOrd ers", _

parentColumn:=m Ds.Tables("Cust omers").Columns ("CustomerId "), _

childColumn:=mD s.Tables("Order s").Columns("Cu stomerId"), _
createconstrain ts:=True))

'Eventhandlers navigatie
Call AddHandlers()

'Some textboxes databinding to the master table
txtCustomerId.D ataBindings.Add ("Text", mDs.Tables("Cus tomers"),
"CustomerId ")
txtCompanyname. DataBindings.Ad d("Text", mDs.Tables("Cus tomers"),
"CompanyNam e")
txtContactname. DataBindings.Ad d("Text", mDs.Tables("Cus tomers"),
"ContactNam e")
txtPostalcode.D ataBindings.Add ("Text", mDs.Tables("Cus tomers"),
"PostalCode ")

'Bind the datagrid to the detail table via the datarelation
grdOrders.DataS ource = mDs.Tables("Cus tomers")
grdOrders.DataM ember =
mDs.Tables("Cus tomers").ChildR elations("relCu stomersOrders") .ToString
grdOrders.ReadO nly = True 'Set the datagrid to READONLY

End Sub

Private Sub AddHandlers()
'Eventhandler navigate-buttons
AddHandler btnFirst.Click, AddressOf Me.Navigate
AddHandler btnNext.Click, AddressOf Me.Navigate
AddHandler btnPrevious.Cli ck, AddressOf Me.Navigate
AddHandler btnLast.Click, AddressOf Me.Navigate
End Sub

Private Sub Navigate(ByVal sender As System.Object, ByVal e As
System.EventArg s)

'grdOrders.Read Only = False '--> This line prevents the
IndexOutOfRange Exception
With Me.BindingConte xt(mDs.Tables(" Customers"))
Select Case sender.name
Case "btnFirst"
.Position = 0
Case "btnPreviou s"
.Position -= 1
Case "btnNext"
.Position += 1
Case "btnLast"
.Position = .Count - 1
End Select
End With
'grdOrders.Read Only = True '<-- This line prevents the
IndexOutOfRange Exception

End Sub
End Class

Nov 21 '05 #8
Coen,

I tried it and no errors (it delays however no exception).

I assume that you have option strict not on, because this row should not be
accepted in my opinion
Select Case sender.name
It has to be
Select Case DirectCast(send er, Button).Name

However that should not give the exception.

Cor
Nov 21 '05 #9
Cor, you are right about the late binding, I have option strict put ON now.
But indeed this is of no influence in this exception matter.

If you are experiencing a delay, something must be happening there. I
suppose you also tried running while all the exceptions set to the "Break
into the debugger" option? Also in your project, something must be causing
the delay...

By the way, using
Dev. env. 7.1.3088
Framework: 1.1.4322 SP1

Coen

"Cor Ligthert" wrote:
Coen,

I tried it and no errors (it delays however no exception).

I assume that you have option strict not on, because this row should not be
accepted in my opinion
Select Case sender.name
It has to be
Select Case DirectCast(send er, Button).Name

However that should not give the exception.

Cor

Nov 21 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
10765
by: kim | last post by:
Scenario (I'm a newbie): I have a datagrid with countries listed and 5 parameters in each row. I want to add a row to this datagrid via an Event Handler. Very basic stuff. This method then call a Business method, which calls a Data method which calls an SP in MS SQL. My code compiles well, but the page throws "Index was outside the bounds of the array". I really can't figure why, take a look maybe you pros see can read between the...
4
3850
by: William McIlroy | last post by:
Array Bounds Exception inside system.xml.dll. Test data is a dozen GB (available for the asking on CD). Source code follows. Call into system.xml.dll happens at the while statement.. using System using System.Xml using System.Collections // This program reads an ASCII file of XML elements // The output is a list of unique NODE TYPEs // For example, <head> produces head in the output // There is no validation of the XML
8
5832
by: Taylor | last post by:
I've run in to code with this pattern: try { // do some potentially bad stuff } catch(System.Exception ex) { throw ex; }
1
2329
by: Joe | last post by:
This is a weird problem. when doing trying to add a tabpage to a tabcontrol I get an error: Index was outside the bounds of the array. Now this only happens when I call a function from within a callback for an Async webmethod call. My guess is that it has something to do with the threads not being in sync yet.
1
4004
by: iCeCLoW | last post by:
Hi there, I´m using the rowFilter property for filtering the rows in a DataView object. If the filter is set to an inexistent value , that is, after filtering i have 0 rows in the DataView, and I try to re-show all the rows again by setting rowFilter = "", after setting the rowStateFilter i obtain the "Index was outside the bounds of the array",. If the dataview is not empty this code works fine. Here is the code: ...
0
1297
by: Trapulo | last post by:
I've a datagrid filled with a collection of objects that inherits from basecollection. When I remove an item from this collection and then click onto the datagrid, I've always this error: "Index was outside the bounds of the array datagrid" I've tried this structure: Dim oldList As Business.MyBaseCollection = DirectCast(dgDetails.DataSource,
10
2230
by: David B | last post by:
I am writing a console App with VB 2005 where I accept a text file as input, parse it and insert the text data into an SQL table. I have written the code correctly as well as I can tell because it works running it within the IDE, given that you have to go into the Debug Project Properties to specify the argument. If I build the file and go run it from the command line, specifying the argument, I get the following error: ...
0
2367
by: Beaker | last post by:
I am having some trouble with an array object and a web service I have. I have a farly simple user object public class User { private Guid myUserId; public Guid UserId { get { return myUserId; }
4
17602
by: weird0 | last post by:
I have no idea why this error this is coming and how can i fix it? Can anyone please help me with it..............? public static class BillManager { private static Object ExecuteSP(Object argArray) { SqlCommand sqlcmd = new SqlCommand(); SqlConnection sqlconnection1 = new SqlConnection(); sqlcmd.Connection = sqlconnection1;
4
3452
by: Arnie | last post by:
Folks, The GZipStream class in .NET is throwing an exception during an OS unseal/power up (first boot experience). The .NET system is fully up as other apps seem to run fine.
0
8383
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8895
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8809
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7407
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6210
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5682
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2797
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2032
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1788
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.