SqlDataAdapter Fill: SelectCommand.Connection property has not been initialized VB.Net

Last Reply on Apr 20, 2015 05:16 AM By Mudassar

Posted on Apr 20, 2015 05:15 AM

Hai ssar.

 

i have this error when i start the program

show on browser

 

Fill: SelectCommand.Connection property has not been initialized.

 

 

Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
Imports CrystalDecisions.ReportSource
Imports System.Data
Imports System.Data.SqlClient
Imports System.Configuration

Public Class WebForm1
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Try
            Dim Query As String = "Select * from TSPPInput"
            Dim constr As String = ConfigurationManager.ConnectionStrings("constr").ConnectionString
            Dim cmd As New SqlCommand(Query)
            Using con As New SqlConnection(constr)


                Dim strReportPath As String = Server.MapPath(String.Format("~/report/CrystalReport1.rpt"))
                If Not IO.File.Exists(strReportPath) Then
                    Throw (New Exception("Unable to locate report file:" & vbCrLf & strReportPath))
                End If

                'con.Open()
                Dim ds As New DataSet()
                Dim dt As New DataTable()

                Dim adp As New SqlDataAdapter(cmd)
                adp.Fill(ds)
                cmd.ExecuteNonQuery()
                dt = ds.Tables(0)

                Dim RD As New ReportDocument
                RD.Load(strReportPath)
                RD.SetDataSource(ds.Tables(0))
                crvTemplate.ReportSource = RD
                ds.Dispose()
                'con.Close()

            End Using

        Catch ex As Exception
            Response.Write(ex.Message.ToString)
        End Try
    End Sub
End Class

please help me. TQ

Posted on Apr 20, 2015 05:16 AM

Add following line

cmd.Connection = con

before

Dim adp As New SqlDataAdapter(cmd)