Solved

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

Posted on 2011-03-10
7
1,194 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
  • 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Excel file not created as expected 7 49
Word Directory is not in the drop down list 4 25
Turn on intranet settings 1 37
Advice on Xojo as a development tool over VB. 4 35
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…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

912 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now