Click here to Skip to main content
11,922,877 members (47,939 online)
Rate this:
Please Sign up or sign in to vote.
See more: VB8.0 VB
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnview.Click
str = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=G:\db1.mdb;Persist Security Info=False"

conn.ConnectionString = str
str = ("select Id,Name,Address,Contact_Number,Vat from table1 where Name='" & sid.Text & "','" & snm.Text & "','" & sadd.Text & "','" & Val(scno.Text) & "','" & Val(svat.Text) & "',")

' If rs.EOF Then

'End If

' If rs.EOF Then

sid.Text = rs.Fields(0).ToString()

snm.Text = rs.Fields(1).ToString()

sadd.Text = rs.Fields(2).ToString()

scno.Text = rs.Fields(3).ToString()

svat.Text = rs.Fields(4).ToString()

bu i got a same error..Item cannot be found in the collection corresponding to the requested name or ordinal. COMEXCEPTION WAS UNHANDLED
Posted 13-Jul-10 5:34am
Edited 13-Jul-10 6:14am
Dylan Morley 13-Jul-10 10:47am
You've specified a field that doesn't exist - how many fields does your SQL statement return

What is the value of rs.Fields.Count? (check the debugger)

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

This error occurs when the names of your data markers do not match the fields of the ADO recordset you are using as your data source.

For example, if your workbook has these data markers:
Then the ADO recordset you assign as a data source must contain fields named "categoryID" and "description".

In order to be sure your ADO recordset has properly named fields, it is a good practice to use those field names explicitly in your SQL query like this:
SELECT categoryID, description FROM categories 
If you use a generic select, as in:
SELECT * FROM categories 
The query will still work if the database has the correct column names. However, it will be significantly less efficient as extra columns will be copied and subsequently ignored.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.151125.1 | Last Updated 13 Jul 2010
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100