Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2011-03-10
7
Medium Priority
?
1,282 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
Stressed Out?

Watch some penguins on the livecam!

 

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

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

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

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
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 viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

721 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