dcsimg
Results 1 to 21 of 21

Thread: [RESOLVED] IndexOUtOfRangeException

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2011
    Location
    Oregon City, Oregon
    Posts
    459

    Resolved [RESOLVED] IndexOUtOfRangeException

    I have a list form that I use to select one or more of the listed people from two tables to add to another table. When I say two tables, they are two tables, each of which hold information on the people listed. They are both related by a primary key of each persons ID number.

    The way this is used, in this case, is that I want to add all of the people from a single department to the form you see behind the first form, which holds the data for a table that I wish to add the selected group of people to. I use the code below to accomplish this task.

    Since I am using combined data from two tables, I use the JoinFillByDepartment query, which is a join query. I have run this in the tableadapter using the query builder and it executes without any problems. However, when execute the routine below, I get the error you see below at the NewTrainingRow.chrJobTitle, line.

    I have checked all of the things I think might cause this type of exception, but have been unable to isolate the problem. Having checked everything I can think of (I am still not done, but I am running out of ideas), I frankly do not understand why there is no row at position 0. To my mind there should be. I have checked both of the tables and the data in the tables and see nothing that should cause the issue.

    Tables
    Name:  related tables.jpg
Views: 337
Size:  47.4 KB

    Form
    Name:  ListForm.jpg
Views: 324
Size:  44.3 KB

    Error
    Name:  Error.jpg
Views: 322
Size:  16.7 KB

    Code:
                'Add group of trainees by department.
                Dim strDepartment As String = CStr(subPickList.cmbDepartment.SelectedValue)
                Dim intRowCount As Integer = 0
                Dim intCountRow As Integer = 0
                'Filter the employee table to include users from a specified department, then count
                'the number of filtered users and return that number.
                intRowCount = CInt(If(subPickList.TblEmployeeTableAdapter.qryReturnActiveDepartment(strDepartment), 0))
                'Add the group of records to the training table.
                subPickList.TblEmployeeTableAdapter.JoinFillByDepartment(subPickList._MasterBase_1_1DataSet.tblEmployee, strDepartment)
                Do Until intCountRow >= intRowCount
                    Dim NewTrainingRow As _MasterBase_1_1DataSet.lnkChangeTrainRow
                    NewTrainingRow = subPickList._MasterBase_1_1DataSet.lnkChangeTrain.NewlnkChangeTrainRow()
                    NewTrainingRow.intEmployeeID = subPickList._MasterBase_1_1DataSet.tblEmployee(intCountRow).intEmployeeID
                    NewTrainingRow.intChangeID = glbintChangeID
                    NewTrainingRow.chrFullName = subPickList._MasterBase_1_1DataSet.tblEmployee(intCountRow).chrFullName
                    NewTrainingRow.chrJobTitle = subPickList._MasterBase_1_1DataSet.lnkEmployeeWork(intCountRow).chrJobTitle
                    NewTrainingRow.chrDepartment = subPickList._MasterBase_1_1DataSet.lnkEmployeeWork(intCountRow).chrDepartment
                    NewTrainingRow.blnRemove = False
                    subPickList._MasterBase_1_1DataSet.lnkChangeTrain.Rows.Add(NewTrainingRow)
                    intCountRow += 1
                Loop
                subPickList.Validate()
                subPickList.lnkChangeTrainBindingSource.EndEdit()
                subPickList.LnkChangeApproveTableAdapter.Update(subPickList._MasterBase_1_1DataSet)
                subPickList.Close()
                SubSignList.LnkChangeTrainTableAdapter.FillByChangeID(SubSignList._MasterBase_1_1DataSet.lnkChangeTrain, glbintChangeID)
            End Sub

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    100,639

    Re: IndexOUtOfRangeException

    What line of your code is the exception being thrown on? You've show the line of auto-generated code that actually throws the exception but not the line of your own code that that gets called from.

    That said, the exception indicates that you're trying to retrieve the first row from a DataTable that contains no rows. If you put a breakpoint on the line of your code that you didn't indicate, then you should be able to simply look at the DataTable in question and see that it has no rows. You can then trace back through your code to where you expected it to be populated with rows and put a breakpoint there and run the code again. You can then see if the table is actually populated or not and, it is, you can step through the code to see where the rows are removed. This is debugging. Set a breakpoint, step through the code and examine the state at each step. Any time you see a state that you didn't expect, you've found the specific location of an issue.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2011
    Location
    Oregon City, Oregon
    Posts
    459

    Re: IndexOUtOfRangeException

    Sorry JM, I thought I had done that. It is the line that begins with NewTrainingRow.chrJobtitle = .....

    I get the error you see below at the NewTrainingRow.chrJobTitle, line.
    It is the line that is looking for a value from the second (related table), lnkEmployeeWork. I have previously set a breakpoint and stepped through the code numerous times. It's called debugging huh? Who would have thought? Having already done that, and knowing the specific location of the issue is the line I previously noted. I also commented that line and the next line throws the same exception (not surprising). I commented out that line as well and the loop carries through. As far as I can tell, there is nothing wrong with the code at the point where the error occurs (although I am somewhat dyslexic and often have a hard time reading a line of code and seeing an obvious error. The same problem I used to have in math and calculus).

    I can see that the issue has to do with the second table. I check the second table and the data exists. So, at this point, I am unclear why I am getting an error that I believe reads that I am trying to pull data from a table that has no rows...….except it does have rows. I am beginning to believe that the issue might lie with the tables, but have been unable to find what I might have done wrong with them for this to occur.

  4. #4
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    32,756

    Re: IndexOUtOfRangeException

    I have very little experience with tableadapters and the strongly typed datatables they create. They do always seem to be more of a black box, and I've said before that you'd probably be happier with raw sql, but despite the obfuscation that MS can put in your way, the first thing I'd be doing is putting a breakpoint on that line and when execution stopped I'd highlight

    subPickList._MasterBase_1_1DataSet.lnkEmployeeWork(intCountRow).chrJobTitle

    (I think that was picked from the right line)

    and press Shift+F9. In fact, I'd be tempted to copy that line to NotePad, or whatever place you can drop text for temporary storage. What Shift+F9 does is brings up a box that shows information, but there's a whole lot of things I'd like to examine in that row, so I would want to be able to tinker with the line in the box that Shift+F9 brings up (I don't know what it's called). First, I'd look at

    subPickList._MasterBase_1_1DataSet.lnkEmployeeWork

    I believe that's a datatable. I would be confirming that the Rows.Count is greater than 0. I'd then be looking at intCountRow to see what that is. Sure, there may not be much question of what that is, but if everything was doing what I expected, then I wouldn't be getting an error, so those first steps are about confirming my assumptions. I'd be assuming these things:

    1) That's a datatable.
    2) That datatable works the way I expect it to.
    3) The datatable has rows.
    4) intCountRow is what I expect it to be.
    5) intCountRow is less than the number of rows in the datatable.

    In my case, with my lack of experience using TableAdapters, the first three would be the most instructive, ideally. If all those assumptions checked out, then I would be quite a bit more interested.
    My usual boring signature: Nothing

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2011
    Location
    Oregon City, Oregon
    Posts
    459

    Re: IndexOUtOfRangeException

    Shaggy,

    That is indeed the correct line. So I set the break point exactly on that line (previously it was at the beginning of the routine). I then highlighted the line and pressed shift-F9. Got nothing. I then allowed it to execute the line, which then threw the exception (thinking I might should do that prior to pressing Shift-F9, with no result. Is there some setting that I do not have on that keeps the box from appearing?

    LnkEmployeeWork is indeed a datatable and it is related to tblEmployee by the EmployeeID number (see the two tables above). I have checked both tables and see nothing wrong with either of them, but here they are anyway (see below). I have run the query noted below from within the dataset using the Query builder and it does execute as expected.

    Wait a minute, I did the Shift-F9 thing one more time and found that I get a message from that at the line in the Dataset Designer where the error is displayed. The message was, "This is the next statement to execute when this thread returns from the current function". No idea what that means, even though it is obviously English. However, I would assume the function is what shows up in the Dataset Designer.

    Wait another minute. I went back to the line in the code where the exception is thrown and was able to get the box (displayed below) to show. I am not sure what it is telling me, but character 17 is the second character in the column name chrJobTitle. This is a column in the table lnkEmployeeWork. What source is it supposed to match?

    Perhaps it is time for me to look into the possibility of raq SQL. Karen has suggested that to me before, but it has fallen on deaf ears. My ears may not be so deaf anymore. Where can I learn how to do that, since tableadapters and bindingsources are all I know (and apparently I do not know them very well)?

    SQL Tables

    Name:  lnkEmployeeWork.jpg
Views: 68
Size:  27.5 KB

    Name:  tblEmployee.jpg
Views: 68
Size:  25.5 KB

    Code:
    SELECT        tblEmployee.intEmployeeID, tblEmployee.chrFirstName, tblEmployee.chrLastName, tblEmployee.chrFullName, tblEmployee.blnObsolete, tblEmployee.btnActive, lnkEmployeeWork.chrJobTitle, lnkEmployeeWork.chrDepartment, lnkEmployeeWork.chrUserName                  
    FROM            lnkEmployeeWork INNER JOIN
                             tblEmployee ON tblEmployee.intEmployeeID = lnkEmployeeWork.intEmployeeID
    WHERE        (tblEmployee.btnActive = 1) AND (lnkEmployeeWork.chrDepartment = @Param1)
    ORDER BY lnkEmployeeWork.chrDepartment
    Name:  Error.jpg
Views: 65
Size:  15.2 KB
    Attached Images Attached Images  

  6. #6
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    32,756

    Re: IndexOUtOfRangeException

    I'm not sure what to make of that. There are several different ways to debug something. My boss and I are both pretty good at it, yet I realize that I don't use a single tool that he uses, and vice versa. Shift+F9 is my goto approach (though I don't use goto) when I want to study something in detail. At any time when executing code in the IDE, pressing Shift+F9 will bring up something. At the top is a textbox where whatever you have selected is displayed (and which you can edit), to the right are a couple buttons to allow you to re-evaluate after editing, and below that is a large DGV with results. What you described doesn't match any of that. I've been using this same technique, and it hasn't changed, in every version of VS from 2003 to 2017.

    I know that some settings can be changed that alter whether you use F10 or F8 to step through code, but I've never heard of Shift+F9 doing anything other than evaluating the currently selected code.
    My usual boring signature: Nothing

  7. #7
    Fanatic Member
    Join Date
    Sep 2017
    Posts
    687

    Re: IndexOUtOfRangeException

    I agree with jm, it looks like you are trying to get a row that does not exist. Not sure what your function looks like, but if "intCountRow " is not > 0 it should return nothing. Same with your loop,

    Code:
             If intCountRow >0
                Do Until intCountRow >= intRowCount
                    Dim NewTrainingRow As _MasterBase_1_1DataSet.lnkChangeTrainRow
                    NewTrainingRow = subPickList._MasterBase_1_1DataSet.lnkChangeTrain.NewlnkChangeTrainRow()
                    NewTrainingRow.intEmployeeID = subPickList._MasterBase_1_1DataSet.tblEmployee(intCountRow).intEmployeeID
                    NewTrainingRow.intChangeID = glbintChangeID
                    NewTrainingRow.chrFullName = subPickList._MasterBase_1_1DataSet.tblEmployee(intCountRow).chrFullName
                    NewTrainingRow.chrJobTitle = subPickList._MasterBase_1_1DataSet.lnkEmployeeWork(intCountRow).chrJobTitle
                    NewTrainingRow.chrDepartment = subPickList._MasterBase_1_1DataSet.lnkEmployeeWork(intCountRow).chrDepartment
                    NewTrainingRow.blnRemove = False
                    subPickList._MasterBase_1_1DataSet.lnkChangeTrain.Rows.Add(NewTrainingRow)
                    intCountRow += 1
                Loop
             End If

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2011
    Location
    Oregon City, Oregon
    Posts
    459

    Re: IndexOUtOfRangeException

    Isn't Row 0 the first row in a table?

    What I have is two tables containing specific information about persons (actually, there are 4 tables but I am only using two of them here), all of which are related. I use the join query, noted above, to pull the required data from the two tables and place them into newly created rows in the table lnkChangeTrain (one row for each filtered record from the other two tables. This is what determines the value of intRowCount). I just ran the routine with intCountRow set at 1 and still got the same exception. Unless I am wrong about the beginning row being row 0 then the value for intCountRow should indeed be 0. The value for intRowCount = 2, which corresponds to the two records matching the parameters of the join query.

    I have used this method previously without any issues, so I know it can work. I suspect that there is something wrong, or missing, in the line where the error occurs, although I cannot see it. As far as I can tell, from running query builder in the dataset, the query is filtering and giving me what I am asking it for.

    The lines, in the loop, prior to the line where the error occurs gets the data from the first table in the query, and the error line (as well as the line after it) gets data from the second table. I read the error as telling me that there is no row from the second table. The query results tell me otherwise. Perhaps I misunderstand completely what the error is actually telling me. Certainly that has happened many times before.

    Name:  queryResult.jpg
Views: 65
Size:  5.6 KB

  9. #9
    Fanatic Member
    Join Date
    Sep 2017
    Posts
    687

    Re: IndexOUtOfRangeException

    Isn't Row 0 the first row in a table?
    Not if the table does not have any rows.

  10. #10
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    100,639

    Re: IndexOUtOfRangeException

    Quote Originally Posted by gwboolean View Post
    I have previously set a breakpoint and stepped through the code numerous times. It's called debugging huh? Who would have thought? Having already done that, and knowing the specific location of the issue is the line I previously noted.
    So have you actually done what I said then?
    Quote Originally Posted by jmcilhinney View Post
    If you put a breakpoint on the line of your code that you didn't indicate, then you should be able to simply look at the DataTable in question and see that it has no rows. You can then trace back through your code to where you expected it to be populated with rows and put a breakpoint there and run the code again. You can then see if the table is actually populated or not and, it is, you can step through the code to see where the rows are removed.
    Have you checked the Rows.Count property of the DataTable when the exception is thrown? The fact that you still seem unsure of whether the table actually contains rows or not seems to suggest that you haven't. What you think should be the case is irrelevant. Only what is matters. The fact that previewing the data a design time shows data only means that there is data to get and that the query will get it if executed. If you're not executing the query at run time though, you're still not going to have any data at run time.

    As someone who has ben doing this for a long time I'm telling you how you should diagnose this issue. Put a breakpoint on the of code that you think should be populating that DataTable. Is that breakpoint hit? Does the DataTable contain rows after that line? If not then that's the issue. If it does but it doesn't later then obviously the rows must be being removed somewhere, so step through the code to find where that happens.

    The steps to diagnose this issue are relatively simple but you seem reticent to perform them and I don't really understand why.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  11. #11

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2011
    Location
    Oregon City, Oregon
    Posts
    459

    Re: IndexOUtOfRangeException

    So have you actually done what I said then.
    Yes JM, I probably did. I say probably, because a lot of what you say is not clear. When I ask you for clarity I frequently do not get that.

    If you put a break point on the line of your code that you didn't indicate.
    What does that mean? I put a break point in a number of different places and track from each of them.

    Have you checked the rows.Count property?
    Yes, I have. I know what it is set to and I know what the value is at the time the exception is thrown.

    The fact that you still seem unsure of whether the table actually contains rows or not seems to suggest you haven't
    I was never unsure that the table actually contains rows. In fact, I provided the table to show that it contained rows.

    What you think should be the case is irrelevant. Only what is matters
    Then instead of wasting time with irrelevant statements tell me what matters.

    The fact that previewing the data at design time shows data only means that there is data to get and that the query will get it if executed.
    Very good. I had thought might be true. Yes JM, there is data to get and the query does get it when executed. Checking that out to make sure that it occurs is what is called testing.

    If you are not executing the query at run time, you're still not going to have any data at run time.
    The query is executed at run time. Had the query not been successfully executed the loop in the routine could not even be started.

    As someone who has been doing this for a long time I'm telling you how you should diagnose the issue.
    Fine Jm. I have been attempting to do that. Can we move past an irrelevant lecture and just survey the problem?

    Put a break point on the code that you think should be populating the DataTable.
    I have done that. The break point is right now on line 258, where the exception is thrown. Is that the wrong place?

    Is that breakpoint hit?
    If you mean does the code stop executing where the break point is then Yes.

    Does the DataTable contain rows after that line?
    On the assumption that the DataTable you refer to is the one that is providing the data, then all I can say is that it is at row 0. I know for a fact that the DataTable contains data and I know for a fact that at the point of the exception that as far as the code is concerned there is no data in the Datatable. I also know that at every step prior to that line there is data available to add to the receiving table. Additionally, I know for a fact (for whatever it is worth) that at line 258 the data comes from a different table than the table used on the previous lines. I also know that if I comment line 258 out and run the loop that the next line will throw the same exception. That line also uses a different table to provide data.

    The steps to diagnose this issue are relatively simple but you seem reticent to perform them and I don't understand why.
    JM, your first instruction was to simply to set breakpoints and step through the code. I did that. Additionally, I identified for you the point at which the error occurred. I do not understand why you believe I did not and I do not understand why you believe that is not the point where the exception occurs. Please explain to me why that would be the case. The only part of your first response I ignored was the where you mentioned that rows are removed. No rows should be removed so I have no idea what you were talking about.

    I know I get openly irritated and frustrated at your approach and should do a better job of not doing that. I am, after all, the one asking for help. On the other side of that coin is that you spend a lot of time making irrelevant statements about what you think I am doing or not doing then providing information that is frequently difficult to get any useful content from. I carry out your suggestions to the extent that they are clear and understandable.

    So at this point I believe I have done all of the things you suggested (as I understand you). Perhaps I have misinterpreted your suggestions, but I have certainly attempted to follow them. Here are the things I believe I know.

    1. I have a query that is successfully executed.
    2. On the assumption that the query, when successfully executed, contains all the data that was called for (and I have no reason to believe that is not true) then I should have a table that contains a subset of rows with columns that has data from two tables.

    3. Each row of the subset of rows (after the query is executed) should contain data in columns 0 = 2 from one table while columns 3 and 4 should contain data from table two.
    3. The code errors at line 258. This is the point at which the data from the second table should exist and be placed into the receiving table. Based on how I read the error, there is not any data in that row. However, it should be the same row that provided the data for the previous columns of the receiving table.

    Name:  Code.jpg
Views: 53
Size:  33.9 KB

  12. #12

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2011
    Location
    Oregon City, Oregon
    Posts
    459

    Re: IndexOUtOfRangeException

    OK, I have worked with this enough to have identified that the query is the source of the issue. It appears that the query is only getting the data from the first table. It is not getting the data from the second table.

    When the query is run from the Tableadapter all of the data from both tables is present. That appears to not be the case when the query is run from the code. Is there an explanation/fix for this that I can understand?

  13. #13

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2011
    Location
    Oregon City, Oregon
    Posts
    459

    Re: IndexOUtOfRangeException

    Problem solved. It turns out that the query must be run from the table lnkEmployeeWork and not tblEmployee. I have no idea why this is, but it is.

  14. #14
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    100,639

    Re: [RESOLVED] IndexOUtOfRangeException

    It's not completely clear but, from what you've said so far, it appears to me that you're expecting one table adapter to populate two DataTables, which isn't going to happen. Even if the query executed by that table adapter retrieves data from multiple database tables, the result set is still going to populate only one DataTable.

    So that we con confirm whether or not this is the case, can you please post the sections of code that I've been referring to throughout this thread, i.e. the part that throws the exception (which seems as though it will be trying to retrieve the first row from a DataTable) and the part that you think is populating that DataTable. If I'm right, the second will not actually be populating the DataTable that the first part is trying to get data from. If I'm wrong, at least that code will confirm that and we can look elsewhere for the cause.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  15. #15
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    100,639

    Re: IndexOUtOfRangeException

    Quote Originally Posted by gwboolean View Post
    Problem solved. It turns out that the query must be run from the table lnkEmployeeWork and not tblEmployee. I have no idea why this is, but it is.
    It's because, as I was posting while you were posted this, because you weren't actually populating the DataTable that you were trying to get data from. I can go into more detail on the why if you want. The issue is exactly what I was getting at in my very first reply so if you had done as I suggest way back then, we'd have solved the issue right away. Here's what I said in post #2:
    You can then trace back through your code to where you expected it to be populated with rows and put a breakpoint there and run the code again. You can then see if the table is actually populated or not
    If you had put a breakpoint on the line that you thought was populating your DataTable and checked whether your DataTable contained rows after it was executed then you'd have seen that it didn't and we could have addressed the reason why there and then.

    I imagine that this will be perceived as a lecture. It's actually a case of pointing out mistakes so that they might not be repeated but I can't make you see it that way. If someone with 15+ years experience of debugging .NET applications suggests that you debug a particular way, there's a good chance that debugging that way will help. You might think that you're doing the right thing but there's a fair chance that, if you were, you wouldn't be asking the question in the first place.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  16. #16

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2011
    Location
    Oregon City, Oregon
    Posts
    459

    Re: [RESOLVED] IndexOUtOfRangeException

    Actually, I have previously used almost identical join queries to do just that. In thinking about it, it would be by guess that when I did this previously it was to display it on the DGV and probably did not actually transfer data from one table to the other. Who knows? Anyway, I actually had to run two queries, one for each TableAdapter. That makes no sense to me, but I am willing to accept it.

    This is the line where the exception was thrown:
    NewTrainingRow.chrJobTitle = subPickList._MasterBase_1_1DataSet.lnkEmployeeWork(intCountRow).chrJobTitle
    Perhaps I did not make that clear, but it always was this line.

    The only change was that I added a second query:
    subPickList.LnkEmployeeWorkTableAdapter.JoinFillByDepartment(subPickList._MasterBase_1_1DataSet.lnkE mployeeWork, strDepartment)

    I am not entirely clear what you are saying JM, and I certainly do not fully understand the process by which the data in a table(s) and queries work together to get data needed to do things with. However, what I believe, in my own vernacular, is that the first query only has data available from the first table and the second query only has data available from the second table. I realize that it probably does not work exactly like that, but that is what the result is. Is that anywhere near what you are stating?

    Code:
           Public Sub AddGroupTrain()
                'Add group of trainees by department.
                Dim strDepartment As String = CStr(subPickList.cmbDepartment.SelectedValue) 'Department selected
                Dim intRowCount As Integer = CInt(If(subPickList.TblEmployeeTableAdapter.qryReturnActiveDepartment(strDepartment), 0)) 'Count number of Employees in department
                Dim intCountRow As Integer = 0
                'Add all employees from a selected department
                subPickList.LnkEmployeeWorkTableAdapter.JoinFillByDepartment(subPickList._MasterBase_1_1DataSet.lnkEmployeeWork, strDepartment)
                subPickList.TblEmployeeTableAdapter.JoinFillByDepartment(subPickList._MasterBase_1_1DataSet.tblEmployee, strDepartment)
                Do Until intCountRow >= intRowCount
                    Dim NewTrainingRow As _MasterBase_1_1DataSet.lnkChangeTrainRow
                    NewTrainingRow = subPickList._MasterBase_1_1DataSet.lnkChangeTrain.NewlnkChangeTrainRow()
                    NewTrainingRow.intEmployeeID = subPickList._MasterBase_1_1DataSet.tblEmployee(intCountRow).intEmployeeID
                    NewTrainingRow.intChangeID = glbintChangeID
                    NewTrainingRow.chrFullName = subPickList._MasterBase_1_1DataSet.tblEmployee(intCountRow).chrFullName
                    NewTrainingRow.chrJobTitle = subPickList._MasterBase_1_1DataSet.lnkEmployeeWork(intCountRow).chrJobTitle
                    NewTrainingRow.chrDepartment = subPickList._MasterBase_1_1DataSet.lnkEmployeeWork(intCountRow).chrDepartment
                    NewTrainingRow.blnRemove = False
                    subPickList._MasterBase_1_1DataSet.lnkChangeTrain.Rows.Add(NewTrainingRow)
                    intCountRow += 1
                Loop
                'Save additions to table
                SubSignList.Validate()
                SubSignList.lnkChangeTrainBindingSource.EndEdit()
                SubSignList.LnkChangeTrainTableAdapter.Update(subPickList._MasterBase_1_1DataSet)
                subPickList.Close()
                'Refresh DGV
                SubSignList.LnkChangeTrainTableAdapter.FillByChangeID(SubSignList._MasterBase_1_1DataSet.lnkChangeTrain, glbintChangeID)
            End Sub

  17. #17

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2011
    Location
    Oregon City, Oregon
    Posts
    459

    Re: [RESOLVED] IndexOUtOfRangeException

    If you had put a breakpoint on the line that you thought was populating your DataTable and checked whether your DataTable contained rows after it was executed then you'd have seen that it didn't and we could have addressed the reason why there and then.
    I don't understand why you keep saying that JM. I did exactly that, as well as many other places. I am not clear what you mean by checked, but the with the check I did, I was able to identify the data that was put into the newly created rows from the first table, and see that there was no data put into the row of the newly created rows from the second table and that there was no data from the second table to put into the newly created row. I knew that from the beginning and that was what led me to believe that the issue might be related to the query.

    I imagine that this will be perceived as a lecture.
    Yes JM, it is.

    It's actually a case of pointing out mistakes so that they might not be repeated but I can't make you see it that way.
    Pointing out mistakes is fine JM, although I am not clear what value I am supposed to gain from having a mistake I already know pointed out. But still fine.

    If someone with 15+ years experience of debugging .NET applications suggests that you debug a particular way, there's a good chance that debugging that way will help.
    That is true JM. However, there was no content to explain what this particular debugging method you suggested was. At least none that I could discern.

    You might think that you're doing the right thing but there's a fair chance that, if you were, you wouldn't be asking the question in the first place.
    I was never claiming that what I was doing was right JM. I was merely doing what I knew how to do.

    What I asked for JM, was for some clarity on something I did not understand and some direction as to what I was doing wrong, as well as the hope of obtaining some direction on how to do it right. That seems to be an appropriate and acceptable expectation to me JM.

  18. #18
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    100,639

    Re: [RESOLVED] IndexOUtOfRangeException

    Quote Originally Posted by gwboolean View Post
    What I asked for JM, was for some clarity on something I did not understand and some direction as to what I was doing wrong, as well as the hope of obtaining some direction on how to do it right. That seems to be an appropriate and acceptable expectation to me JM.
    Yes, but we need some clarity too. We don't know what you know or don't know unless you tell us. We don't know what you did or did not do unless you tell us. We can't tell you what the solution to your problem is if we don't understand your problem. If you tell us that the error message says that there's no row at index 0 and also tell us that your table definitely contains rows then we can't provide a solution because you're describing that situation that either doesn't exist or is the result of something on your system being broken. It appears - and I'm sure that I'm not the only one who suspected this - that you were describing a situation that didn't exist. Your table did, in fact, not contain any rows.

    The next step in the process is to determine WHY it doesn't contain any rows. That is why I repeatedly told you to place a breakpoint on the line of code that you thought was responsible for adding rows to that table. Now that you have fixed your issue, this is the line that ACTUALY adds those rows:
    The only change was that I added a second query:
    subPickList.LnkEmployeeWorkTableAdapter.JoinFillByDepartment(subPickList._MasterBase_1_1DataSet.lnkE mployeeWork, strDepartment)
    Surely, before you added that line of code, you must have thought that some other line was going to be adding those rows. If not, how did you think the rows were going to get there? If you place a breakpoint on that line of code that you added and then run your project, you'll be able to see that the DataTable in question, i.e.subPickList._MasterBase_1_1DataSet.lnkEmployeeWork, contains no rows before that line is executed and it does contain rows afterwards. That is what I was telling you to do with whatever line of code you previously thought was going to add those rows. If you had done that then you would have seen that the table still had no rows in it afterwards and you'd know that your belief that that line would add the rows was the issue. You could then post that line of code and then we would be able to explain the issue and provide the solution because we would actually have all the relevant information.

    I think the root issue here is that you are not properly distinguishing between your DataSet and your database. That is not uncommon. The DataSet is not the database. A DataSet often has the same schema as the database but it is not the database. A DataSet object is just a data structure. It contains data. That data often comes from a database - usually in fact - but it's still just an object that stores data.

    Your DataSet contains pairs of DataTables and table adapters. The only way to get data from the database into a DataTable is to call a method on the corresponding table adapter. The line of yours that I quote above does that for subPickList._MasterBase_1_1DataSet.lnkEmployeeWork. Without that line, that DatatTable will be empty. It doesn't matter what other queries you execute using what other table adapter to populate what other DataTables. Unless you populate that specific DataTable, it will remain unpopulated. What I have been doing all along is trying to get you top identify the line of code that you thought was doing that populating and observe that it actually wasn't doing that.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  19. #19

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2011
    Location
    Oregon City, Oregon
    Posts
    459

    Re: [RESOLVED] IndexOUtOfRangeException

    Yes, but we need some clarity too. We don't know what you know or don't know unless you tell us. We don't know what you did or did not do unless you tell us.
    I made an effort to tell you JM. I explained and displayed what occurred, and even pointed out the exact point it occurred, as well as what I thought was occurring. All you had to do is was indicate to me that I was right/wrong and offer some direction/suggestions as to how to get on track.

    If you tell us that the error message says that there's no row at index 0 and also tell us that your table definitely contains rows then we can't provide a solution because you're describing that situation that either doesn't exist or is the result of something on your system being broken.
    I told you what the message said then displayed the message JM. That should have been clear, but if not certainly you could have just asked for clarification and I would have made an attempt to do so.

    It appears - and I'm sure that I'm not the only one who suspected this - that you were describing a situation that didn't exist. Your table did, in fact, not contain any rows.
    My description of what occurred was never anything but my best guess based on my observations. It is appears that you knew even then what was going on and instead of offering useful information you chose to tell me to set a break point at the location of the exception and see if there was data there. Since I had already done that and had stated that I had done that I naturally assumed you had not bothered to read what I stated. Or perhaps what I said was poorly crafted and lacked understandable content concerning the system and process and what I stated was not clear to you. A normal response would have been to explain that you had no idea what I was saying and see if perhaps I might be able to clarify what I was saying.

    The next step in the process is to determine WHY it doesn't contain any rows. That is why I repeatedly told you to place a breakpoint on the line of code that you thought was responsible for adding rows to that table. Now that you have fixed your issue, this is the line that ACTUALY adds those rows:
    I repeatedly followed that step JM and had carried out that step prior to even beginning the thread. A normal response would have been to suggest that I was incorrect in my analysis of the situation and perhaps offer a description of what the correct analysis might be and how to go about testing and observing the process. That was not what you did JM.

    What I have been doing all along is trying to get you top identify the line of code that you thought was doing that populating and observe that it actually wasn't doing that.
    What I have been doing all along is indicate to you that I had identified the line of code that I thought was doing the populating and that I had observed that it actually wasn't doing that. You were unwilling to do anymore than repeatedly tell me to do exactly what I had already done.

    I am the amateur, supplicant if you will, and you are the professional who has the ability, knowledge and skills that I lack. In a normal world I, the amateur, make a mistake or have a problem (due to my lack of ability, knowledge and skill). I then, to the best of my lack of ability, knowledge and skill, provide you (the professional) with my assessment/observations. The normal expectation would be for you to provide information from you about the system and process such that I can see where I went wrong and why and even perhaps obtain additional information that would enhance my ability, knowledge and skills. This is what anyone who is observing the principles of Good Engineering Practice would do.

    On infrequent occasions, JM, you do provide very helpful and concise instruction and direction. More often all you provide is a lecture telling me that I should not do what you are doing and providing nothing of significant value. This is a case in point, since your total offering was to suggest that I do what I had already done and that I should completely understand the system and process by doing so.

    JM, I am curious. How is it that someone who has 15 years professional experience could have almost know concept of Good Engineering Practice?



  20. #20
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    32,756

    Re: [RESOLVED] IndexOUtOfRangeException

    Your good engineering practice appears to be clearly focused on some kind of mechanical or structural engineering. Software engineering has a radically different weighting of principles. For one thing, the materials cost is nearly zero.
    My usual boring signature: Nothing

  21. #21

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2011
    Location
    Oregon City, Oregon
    Posts
    459

    Re: [RESOLVED] IndexOUtOfRangeException

    Absolutely true Shaggy. I was Chemical Engineering, not structural by the way. All areas of Engineering, including software, share the same concepts, principles, approaches, logic and methodology. The focus of all engineering starts with the concept of a systems and processes.

    A good point in case. Almost every Engineer, of any stripe, that has anything to do with any kind of automated process uses and programs PLCs, using Ladder Logic. Admittedly, PLCs are limited in their capabilities and therefore the software written for them are not generally very complex. Having said that, they are indeed software and would follow an identical process for design, development, implementation, usage and maintenance as would anything mechanical, electrical, chemical, biological, etc.

    Having said all of that, I will always look at design, development, testing, etc. through a lens colored towards Chemistry and Biologicals.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width