Click here to Skip to main content
15,879,535 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
conn.Open()
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
'rs.AddNew()

'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
Updated 13-Jul-10 5:14am
v5
Comments
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

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:
%%=categoryID
%%=description
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:
SQL
SELECT categoryID, description FROM categories 

If you use a generic select, as in:
SQL
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.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900