Link to home
Start Free TrialLog in
Avatar of Varshini S
Varshini S

asked on

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

        xl.Workbooks.Open("C:\TEMP\ITEM.CSV")

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

        'all your data objects here like connection and command

        Dim dr As SqlDataReader

        Try

            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
            MessageBox.Show(ex.Message)
        End Try

    End Sub

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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?
Avatar of Varshini S
Varshini S

ASKER

Wayne Taylor (webtubbs) : i would like to read excel sheet and assign the values to data reader.
Wayne Taylor (webtubbs) : i would like to read excel sheet and assign the values to data reader. i would like to use ADO.Net.
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?
Reason for using ADO.NET is  want to assign the cell values to data reader object.