2 Replies - 11908 Views - Last Post: 06 July 2011 - 12:42 AM Rate Topic: -----

#1 Elda  Icon User is offline

  • D.I.C Regular

Reputation: 31
  • View blog
  • Posts: 314
  • Joined: 30-December 10

ExecuteReader: CommandText property has not been initialized

Posted 05 July 2011 - 11:56 PM

Hello...

I have this code in form1 at buttonpreview

 Dim Report1Form As New Form2
        Dim TableName(0) As String
        Dim QueryString(0) As String
        TableName(0) = "MIS_WO" 'Pass The Table That you used in the crystal Report
        QueryString(0) = strSQL ' Pass the Query
        Report1Form.ViewReport(TableName, QueryString, New CrystalReport3)
        Report1Form.Show()



And this code in form2 with CrystalReportViewer

 Public Function GetDataAdeptor(ByVal QueryString As String) As SqlDataAdapter

        Dim DataAdapter As New SqlDataAdapter

        Dim NewConnection As SqlConnection = OpenNewConnection()
        DataAdapter = New SqlDataAdapter(QueryString, NewConnection)
        Return DataAdapter


    End Function



 Public Function OpenNewConnection() As SqlConnection

 Dim NewConnection As New SqlConnection("connectionstring")

        Try
            NewConnection.Open()
            Return NewConnection
        Catch ex As Exception
            Throw (ex)
        End Try

    End Function


 Friend Sub ViewReport(ByVal TableName() As String, ByVal QueryString() As String, ByVal Report As CrystalDecisions.CrystalReports.Engine.ReportDocument)



        Dim Adapter As New SqlClient.SqlDataAdapter
        Dim DataSet As New DataSet
        For I As Integer = 0 To UBound(TableName)
            Adapter = GetDataAdeptor(QueryString(I))
           Adapter.Fill(DataSet, TableName(I))'====== Error highlight this line...... 
        Next

        Report.SetDataSource(DataSet)
        CrystalReportViewer1.ReportSource = Report



    End Sub






But everytime I hit the preview button, it gave me error
"ExecuteReader: CommandText property has not been initialized"




What do I missed? Please help me figured out... Thanks....

This post has been edited by Elda: 06 July 2011 - 12:01 AM


Is This A Good Question/Topic? 0
  • +

Replies To: ExecuteReader: CommandText property has not been initialized

#2 noorahmad  Icon User is offline

  • Untitled
  • member icon

Reputation: 209
  • View blog
  • Posts: 2,290
  • Joined: 12-March 09

Re: ExecuteReader: CommandText property has not been initialized

Posted 06 July 2011 - 12:10 AM

You are missing SQL Select query to assing to SqlCommand object

dim str as String = "SELET * FROM tablename"
dim cmd as new SqlCommand
cmd.CommandText = str // <-- Here...


Was This Post Helpful? 1
  • +
  • -

#3 Elda  Icon User is offline

  • D.I.C Regular

Reputation: 31
  • View blog
  • Posts: 314
  • Joined: 30-December 10

Re: ExecuteReader: CommandText property has not been initialized

Posted 06 July 2011 - 12:42 AM

Ok... I got it Sir...

Thank you so much... :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1