473,657 Members | 2,445 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Index was out of range. Must be non-negative and less than the size of the collection Error

Pat
I have a 3 Datagrids.
The dtgMaster is the main datagrid and after selecting a ROW i populate the
second datagrid dtgDetails and the same for
the 3rd datagrid dtgChild.
But the thing is after clicking on a ROW on the dtgMaster and then select a
ROW in the second datagrid and the go back to the
dtgMaster which is the main datagrid and try to PAGE i get the error

"Index was out of range. Must be non-negative and less than the size of the
collection. Parameter name: index"

At the line
Dim strFilter As String =
CStr(dtgDetails .DataKeys(dtgDe tails.SelectedI ndex)).Replace( "'", "''")
of the second DataGrid

Any ideas

Sub BindMaster()
Dim strQuery As String = "Select OrderID,Invoice Date,OrderDate From
CMRC_Orders ORDER BY " & viewstate("sort Field").ToStrin g & " " &
viewstate("sort Direction").ToS tring

'Dim objConn As SqlConnection = New
SqlConnection(C onfigurationSet tings.AppSettin gs("ConnectionS tring"))

Dim dataAdapter As New SqlDataAdapter( strQuery, objConn)
Dim ds As New DataSet

dataAdapter.Fil l(ds)
dtgMaster.DataS ource = ds
'dtgMaster.Curr entPageIndex = 0
dtgMaster.DataB ind()

End Sub

Sub BindDetails()
' getting the filter value from the master Grid's DataKeys
collection

If dtgMaster.Selec tedIndex <> -1 Then

Dim strFilter As String =
CStr(dtgMaster. DataKeys(dtgMas ter.SelectedInd ex)).Replace("' ", "''")
Dim strQuery As String = "Select t1.OrderDetailI D, t1.OrderID,
where t1.OrderID = '" & strFilter & "'"
Dim dataAdapter As New SqlCommand(strQ uery, objConn)

objConn.Open()
dtgDetails.Data Source = dataAdapter.Exe cuteReader()

End If
dtgDetails.Data Bind()

End Sub


Sub BindChild()
If dtgDetails.Sele ctedIndex <> -1 Then
'Dim objConn As SqlConnection = New
SqlConnection(C onfigurationSet tings.AppSettin gs("ConnectionS tring"))

'Error here
Dim strFilter As String =
CStr(dtgDetails .DataKeys(dtgDe tails.SelectedI ndex)).Replace( "'", "''")

'Dim strQuery As String = "Select t3.Feature from Orders where
t1.OrderDetailI D= '" & strFilter & "'"

Dim dataAdapter As New SqlCommand(strQ uery, objConn)
objConn.Open()

dtgChild.DataSo urce =
dataAdapter.Exe cuteReader(Comm andBehavior.Clo seConnection)

'Response.Write ("<b>" & strFilter & "</b>")

End If
dtgChild.DataBi nd()
End Sub
Nov 19 '05 #1
0 7210

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

Similar topics

2
10339
by: skura | last post by:
I am trying to understand how the data in sql server is stored and also regarding fill factor and page splitting. 1) My first question what is the difference between Index pages and Data pages. and how are they different for clustered and non clustered indexes and heap tables. 2) What is the relation between index and data pages.
4
1538
by: DC | last post by:
When a nonunique nonclustered index is built on top of a clustered index, is it guaranteed that the bookmark in the nonclustered index will be kept in the same order as the clustered index? Here's an example to demonstrate my question: CREATE TABLE indextest (col1 int NOT NULL,col2 int NOT NULL,col3 int,col4 int) ALTER TABLE indextest ADD PRIMARY KEY CLUSTERED (col1,col2) CREATE INDEX ix_indextest ON indextest (col1,col3)
14
2237
by: Craig O'Shannessy | last post by:
Hi all, Just thought I'd mention that I really think this problem needs to be fixed. I I'm patching the 7.4RC1 JDBC drivers as we speak due to this optimiser bug, and it's the third time I've had to do this. I would think this bug causes quite a lot of people to evaluate postgres and decide it has awful primary key performance! I love postgres, and hate to think that this could be happening.
13
13395
by: Chameleon | last post by:
I am programming in C++ for 4 years, so I am not a newbie but I am not a very experienced programmer on standard C++ libary. My question is this: Can you tell me one case which an iterator is better than index? For me (until now) iterators are very strangely objects because they are useless for me. But since most of members of containers use iterators, I am stumped.
15
6471
by: rAinDeEr | last post by:
Suppose i have a table which holds thousands of records with the following structure CREATE TABLE "test "."T_CNTRY" ( "CNTRY_CDE" CHAR(2) NOT NULL , "CNTRY_NAME" VARCHAR(50) ) and i have Created an index like below ::
14
22556
by: micklee74 | last post by:
hi say i have string like this astring = 'abcd efgd 1234 fsdf gfds abcde 1234' if i want to find which postion is 1234, how can i achieve this...? i want to use index() but it only give me the first occurence. I want to know the positions of both "1234" thanks
35
29216
by: erikwickstrom | last post by:
Hi all, I'm sorry about the newbie question, but I've been searching all afternoon and can't find the answer! I'm trying to get this bit of code to work without triggering the IndexError. import shutil, os, sys
85
4285
by: Russ | last post by:
Every Python programmer gets this message occasionally: IndexError: list index out of range The message tells you where the error occurred, but it doesn't tell you what the range and the offending index are. Why does it force you to determine that information for yourself when it could save you a step and just tell you? This seems like a "no-brainer" to me. Am I missing something?
0
1659
by: muzu1232004 | last post by:
If I have a table t1 with a column a as follows A 1 1 1 1 1 1 1
1
3209
by: Steffen Stellwag | last post by:
Truely is often better to scan a table in full passing by an index , but if you can force the optimizer to use an index via a hint for testing and comparing the results. But the index in the above example is not used , because the hint is malformed, if tables in a Select statment are named by aliases you have to specify the alias name in the hint statment , not the table name /*+ INDEX (ICWOIMP PK_ICWOIMP) */ change to /*+ INDEX (A...
0
8395
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8826
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
8732
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...
1
8503
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7330
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...
0
5632
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();...
0
4306
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1955
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1615
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.