VB.NET Application throwing an error - Public member 'ExecuteReader' on type 'applicationClass' not found.

when i execute the following code i got this exception

Public member 'ExecuteReader' on type 'applicationClass' not found. How do i fix this ?

Imports Excel = Microsoft.Office.Interop.Excel
Imports System.Data.SqlClient

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim xl As New Microsoft.Office.Interop.Excel.Application

        Dim wSheet As Excel.Worksheet


        wSheet = xl.Workbooks("ITEM.CSV").Sheets("ITEM")

        'all your data objects here like connection and command

        Dim dr As SqlDataReader


            dr = xl.ExecuteReader

            If dr.HasRows Then
                While dr.Read()
                    wSheet.Cells(1, 1) = dr.Item("SomeColumnName")
                    wSheet.Cells(1, 2) = dr.Item("SomeOtherColumnName")
                End While
            End If
        Catch ex As Exception
        End Try

    End Sub

Open in new window

Varshini SAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
>>dr = xl.ExecuteReader

xl is referring to an Excel.Application object, it does not have a method called "ExecuteReader".

you can try see and modify from this example instead

C# ADO.NET SqlCommand - ExecuteReader

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Wayne Taylor (webtubbs)Commented:
You are mixing up 2 methods of interacting with Excel. You can use the Excel.Application object, or you can use ADO.Net.

What is it you are trying to do?
Varshini SAuthor Commented:
Wayne Taylor (webtubbs) : i would like to read excel sheet and assign the values to data reader.
Fundamentals of JavaScript

Learn the fundamentals of the popular programming language JavaScript so that you can explore the realm of web development.

Varshini SAuthor Commented:
Wayne Taylor (webtubbs) : i would like to read excel sheet and assign the values to data reader. i would like to use ADO.Net.
Jacques Bourgeois (James Burger)PresidentCommented:
Is there a good reason why you want to use ADO.NET instead of going straight to Excel as you could do by using your wSheet variable with stuff such as wSheet.Cells(3,5).Value?
Varshini SAuthor Commented:
Reason for using ADO.NET is  want to assign the cell values to data reader object.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.