Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2008-06-22
10
Medium Priority
?
1,317 Views
Last Modified: 2008-06-22
Ok guys i cant work out why i keepp getting this message, i have check the debug.print out putin access and it works with no problems, and i have checked to make sure that this information is in the database and all the spelling is correct and it is, i guess  if it wasnt it wouldnt be working in access the out put i am getting in the debug windows is

 select * from [Student_Outcomes] where [OutcomeDate]  = #10/09/2007# And [StudentID] = 60

and then a message

A first chance exception of type 'System.Runtime.InteropServices.COMException' occurred in adodb.dll

Thanks in advance guys

Dim rs As New ADODB.Recordset
        Dim sql As String
        sql = "select * from [Student_Outcomes] where [OutcomeDate]  = #" & ListView2.SelectedItems.Item(0).SubItems(1).Text & "# And [StudentID] = " & TextBox7.Text
        Debug.Print(sql)
        studentnotes.Text = ""
        studentnotes.Text = (rs.Fields("OutcomeNotes").Value)
        rs.Close()

Open in new window

0
Comment
Question by:awolarczuk
[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
  • 4
  • 2
10 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 21840017
where is your rs.open statement?
0
 
LVL 24

Expert Comment

by:purplepomegranite
ID: 21840019
Your code snippet is incomplete, so it is difficult to tell what code is elsewhere with regards to the database connection.  However, while you declare the sql string, there is no declaration to actually populate the rs recordset with the result of this query?

Code should be something like attached (I presume the bits I've added at the front you already have).
' Connect to database
Dim ConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=c:\\Northwind.mdb"
Dim conn As Connection = New Connection
Dim connMode As Integer = ConnectModeEnum.adModeUnknown
conn.CursorLocation = CursorLocationEnum.adUseServer
conn.Open(ConnectionString, "", "", connMode)
Dim cmdType As Integer = CommandTypeEnum.adCmdText
 
 
Dim sql As String
sql = "select * from [Student_Outcomes] where [OutcomeDate]  = #" & ListView2.SelectedItems.Item(0).SubItems(1).Text & "# And [StudentID] = " & TextBox7.Text
Debug.Print(sql)
' Run query
Dim rs As _Recordset = conn.Execute(sql)
studentnotes.Text = ""
studentnotes.Text = (rs.Fields("OutcomeNotes").Value)
rs.Close()

Open in new window

0
 

Author Comment

by:awolarczuk
ID: 21840093
ok guys i have got it working now thanks so much, how could i have miss that but now i am getting another error that i thought the code i am using should have fixed

{"Either BOF or EOF is True, or the current record has been deleted. Requested operation requires a current record."}

is below
Private Sub ListView2_MouseHover(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListView2.MouseHover
        Dim rs As New ADODB.Recordset
        Dim sql As String
        sql = "select * from [Student_Outcomes] where [OutcomeDate]  = #" & ListView2.SelectedItems.Item(0).SubItems(1).Text & "# And [StudentID] = " & TextBox7.Text
        Debug.Print(sql)
        rs.Open(sql, cnn1, ADODB.CursorTypeEnum.adOpenDynamic, ADODB.LockTypeEnum.adLockPessimistic)
        studentnotes.Text = ""
        If Not DBNull.Value.Equals(rs.Fields("OutcomeNotes").Value) Then
            studentnotes.Text = ""
            studentnotes.Text = rs.Fields("OutcomeNotes").Value
        Else
            studentnotes.Text = "Currently There are no notes to Display for this Student"
            rs.Close()
        End If
 
        rs.Close()
    End Sub

Open in new window

0
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 

Author Comment

by:awolarczuk
ID: 21840096
i have also tried it like this
    Private Sub ListView2_MouseHover(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListView2.MouseHover
        Dim rs As New ADODB.Recordset
        Dim sql As String
        sql = "select * from [Student_Outcomes] where [OutcomeDate]  = #" & ListView2.SelectedItems.Item(0).SubItems(1).Text & "# And [StudentID] = " & TextBox7.Text
        Debug.Print(sql)
        rs.Open(sql, cnn1, ADODB.CursorTypeEnum.adOpenDynamic, ADODB.LockTypeEnum.adLockPessimistic)
        studentnotes.Text = ""
        studentnotes.Text = rs.Fields("OutcomeNotes").Value
        rs.Close()
    End Sub
and get a type 'DBNull' to type 'string' is not valid
    Private Sub ListView2_MouseHover(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListView2.MouseHover
        Dim rs As New ADODB.Recordset
        Dim sql As String
        sql = "select * from [Student_Outcomes] where [OutcomeDate]  = #" & ListView2.SelectedItems.Item(0).SubItems(1).Text & "# And [StudentID] = " & TextBox7.Text
        Debug.Print(sql)
        rs.Open(sql, cnn1, ADODB.CursorTypeEnum.adOpenDynamic, ADODB.LockTypeEnum.adLockPessimistic)
        studentnotes.Text = ""
        studentnotes.Text = rs.Fields("OutcomeNotes").Value
        rs.Close()
    End Sub

Open in new window

0
 
LVL 24

Expert Comment

by:purplepomegranite
ID: 21840189
BOF or EOF true basically means that your SQL statement isn't returning any data.

You have a debug statement for the sql.  Please paste the generated SQL here - either there is a problem with your generation of the SQL, or there is actually no data that matches your query.
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 21840191
that error means that you got no records back:
  Private Sub ListView2_MouseHover(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListView2.MouseHover
        Dim rs As New ADODB.Recordset
        Dim sql As String
        sql = "select * from [Student_Outcomes] where [OutcomeDate]  = #" & ListView2.SelectedItems.Item(0).SubItems(1).Text & "# And [StudentID] = " & TextBox7.Text
        Debug.Print(sql)
        rs.Open(sql, cnn1, ADODB.CursorTypeEnum.adOpenDynamic, ADODB.LockTypeEnum.adLockReadOnly)
        studentnotes.Text = ""
        if not (rs.eof and rs.bof) then
           studentnotes.Text = rs.Fields("OutcomeNotes").Value
        end if
        rs.Close()
    End Sub

Open in new window

0
 

Author Comment

by:awolarczuk
ID: 21840200
ok mate thanks so much i am more then happy to give you 500 point for the extra help but bnow i am gettting

Conversion from type 'DBNull' to type 'String' is not valid.
on hte same line

any help mate please
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 21840209
that means that the value returned could be NULL.
you have 2 options:

* make the NULL value replaced by the query
sql = "select NZ(OutcomeNotes, 'N/A') OutcomeNotes from [Student_Outcomes] where [OutcomeDate]  = #" & ListView2.SelectedItems.Item(0).SubItems(1).Text & "# And [StudentID] = " & TextBox7.Text
 
* handle the NULL value in the .net code
Private Sub ListView2_MouseHover(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListView2.MouseHover
        Dim rs As New ADODB.Recordset
        Dim sql As String
        sql = "select * from [Student_Outcomes] where [OutcomeDate]  = #" & ListView2.SelectedItems.Item(0).SubItems(1).Text & "# And [StudentID] = " & TextBox7.Text
        Debug.Print(sql)
        rs.Open(sql, cnn1, ADODB.CursorTypeEnum.adOpenDynamic, ADODB.LockTypeEnum.adLockReadOnly)
        studentnotes.Text = ""
        if not (rs.eof and rs.bof) then
          if not IsDBNull(rs.Fields("OutcomeNotes").Value)
           studentnotes.Text = rs.Fields("OutcomeNotes").Value
          end if
        end if
        rs.Close()
    End Sub

Open in new window

0
 

Author Comment

by:awolarczuk
ID: 21840253
ok i think the code is working but it is changing all my date back to us format how can i keep them the way they are or state that they are aus format
0
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 2000 total points
ID: 21840272
ms access uses the US format for "storing/recognizing" the dates.
for display in another format, you need to format the date value as needed, in access query that could be the Formatdatetime() function:
http://office.microsoft.com/en-us/access/HA012288411033.aspx
0

Featured Post

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Question has a verified solution.

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

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

636 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