Solved

error - 3265 Item cannot be found in the collection corresponding to the requested name or ordinal

Posted on 2011-03-10
7
1,254 Views
Last Modified: 2012-06-21
I have inherited the maintenance and development of a VB .NET application.  I am on a learning curve with VB .NET 2010 as previously I have only done small things.  When my program attempts to perform an insert into a table I am getting a 3265 error  "Item cannot be found in the collection corresponding to the requested name or ordinal..."  I have not changed the field.  I have experimented and commented out various target fields but it always fails.  Pardon the 'old school cobol db2 speak' but it is as if the table has not been declared(no dclgen) but for the first field. "grstMembership.Fields("Sin").Value = gstrSIN"  no problem
The program blows up on: ".Fields("LastName").Value = Trim(txtLastName.Text)"


When the program executes:  DbHelper.OpenADODBConnection
it simply does a:  select 1 from table.
this connection is successful

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
         If gstrAction = "AddMember" Then

           
            grstMembership = New ADODB.Recordset
            grstMembership.CursorLocation = ADODB.CursorLocationEnum.adUseClient
            grstMembership.Open(gstrSQL, DbHelper.OpenADODBConnection, ADODB.CursorTypeEnum.adOpenKeyset, ADODB.LockTypeEnum.adLockOptimistic)
            gstrSIN = ConvertSINToDatabase(mskSIN.Text)
           
            grstMembership.AddNew()
           
            grstMembership.Fields("Sin").Value = gstrSIN
         End If


         Dim deceasedMessage As String
         With grstMembership

            'update data
            If gstrAction = "AddMember" Or gstrAction = "ChgMember" Then
                               
                .Fields("LastName").Value = Trim(txtLastName.Text)       <<<<<<<<<<< point of failure
                .Fields("FirstName").Value = Trim(txtFirstName.Text)
                .Fields("Gender").Value = cboSex.Text
                .Fields("BirthDate").Value = ConvertDateToDatabase(mskBirthDate.Text)
                .Fields("AddressEffDate").Value = ConvertDateToDatabase(mskEffDate.Text)

                ... blah blah blah

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
0
Comment
Question by:davidkjohnson
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 35100773
To do what you are doing you need to alter your SQL statement to pull back all of the columns you want to write to. "SELECT 1 FROm ***" will only pull back the first column in the table.
0
 

Author Comment

by:davidkjohnson
ID: 35122537
I changed the select 1 from table to read select * from table and continue to get the same results.  This was something I did earlier to resolve the problem unsuccessfully.  Further potential solutions are most welcome.  One thing I have noticed is that even in debug mode I cannot see the record fully defined.  I am wondering whether there is a way to see it.
0
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 35125965
You need to check precisely what columns your SQL statement is returning. Your code is expecting a column called "LastName", but the error says there isn't a column with that name, so there is a discrepancy somewhere.

Also, if this is ASP.Net, why are you using ADODB rather than the .Net data objects?
0
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 

Author Comment

by:davidkjohnson
ID: 35128444
Thank you Carl,
It is VB .NET code that I have inherited.  As a COBOL DB2 programmer I am used to defining data fields explicitly in a DCLGEN of the 'data division.'  I don't fully understand why the original programmers did things the way they did them.

I am trying to find a way that I can see the contents of the recordset to determine if the code is initializing it somewhere where I don't want it to.

0
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 35128479
The only potential issue I can see with your code is that you only initialize the recordset if "gstrAction" is "AddMember". If it is "ChgMember" then it will still get to the code that tries to write to the recordset, but it doesn't get initialized anywhere in that scenario (unless it has just been omitted from your post)
0
 

Accepted Solution

by:
davidkjohnson earned 0 total points
ID: 35150221
As I mentioned this was an application that I had inherited.  Unfortunately there is a lack of documentation, lack of comments in the programs, a complete absence of documented test cases\results et cetera.  The source code version and the production application were not in synch.

I inserted the line of code during a round of elimination and found that it worked.  Previously I may have inserted the code into the called module instead of the calling module.  This is all part of the learning curve.

If gstrAction = "AddMember" Then
            gstrSQL = "select * from membership"                                   <<< added this line

grstMembership.CursorLocation = ADODB.CursorLocationEnum.adUseClient
            grstMembership.Open(gstrSQL, DbHelper.OpenADODBConnection, ADODB.CursorTypeEnum.adOpenKeyset, ADODB.LockTypeEnum.adLockOptimistic)
            gstrSIN = ConvertSINToDatabase(mskSIN.Text)
           
            grstMembership.AddNew()
           
            grstMembership.Fields("Sin").Value = gstrSIN
         End If


         Dim deceasedMessage As String
         With grstMembership

            'update data
            If gstrAction = "AddMember" Or gstrAction = "ChgMember" Then
                               
                .Fields("LastName").Value = Trim(txtLastName.Text)       <<<<<<<<<<< point of failure
                .Fields("FirstName").Value = Trim(txtFirstName.Text)
                .Fields("Gender").Value = cboSex.Text
                .Fields("BirthDate").Value = ConvertDateToDatabase(mskBirthDate.Text)
                .Fields("AddressEffDate").Value = ConvertDateToDatabase(mskEffDate.Text)

                ... blah blah blah

0
 

Author Closing Comment

by:davidkjohnson
ID: 35178800
I knew the problem was that the fields weren't being defined but I couldn't find in the program an example of how the field definitions were created and couldn't find examples of this in any of the text books.
Through trial and error, thick headed stubborness and a little knowledge I resolved one of my own problems.
0

Featured Post

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There is an easy way, in .NET, to centralize the treatment of all unexpected errors. First of all, instead of launching the application directly in a Form, you need first to write a Sub called Main, in a module. Then, set the Startup Object to th…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This video teaches viewers about errors in exception handling.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

630 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question