hi I'm having problems in my crystal report where all the selected rows in my datagrid will show up in my crystal report but instead it showing me an exception selectcommand.connection has not been initialized

here's my code in my form where the datagrid is:

            Dim cmd As OleDbCommand = New OleDbCommand("SELECT Data1.ID, Data1.DateFile as [Date File] , Data1.Plate as [Plate #], Data1.Driver as Driver, Data1.EmpID as EmpID, Data1.OdometerBefore As [Odometer Before], Data1.OdometerAfter As [Odometer After], Data1.Gas as Gas, Data1.CostofGas as [Cost of Gas] FROM Data1", con)
            con.Open()
            adpt = New OleDbDataAdapter(cmd)
            'Here one CommandBuilder object is required.
            'It will automatically generate DeleteCommand,UpdateCommand and InsertCommand for DataAdapter object  
            Dim builder As OleDbCommandBuilder = New OleDbCommandBuilder(adpt)
            DtSet = New DataSet()
            adpt.Fill(DtSet, "Data1")
            DataGridView1.DataSource = DtSet.Tables("Data1").DefaultView
            DataGridView1.Columns(0).Visible = False
            con.Close()
            con = Nothing

here's my code in my crystal report. my crystal report will show once a button is clicked from the previous form and my connection is in public

 Dim cmd As New OleDbCommand("Select * From Data1 Where DateFile = " & Form4.DataGridView1.SelectedRows(0).Cells(0).Value.ToString() & "", Form4.con)
        Dim adpt As New OleDbDataAdapter(cmd)
        Dim DtSet As New DataSet
        adpt.Fill(DtSet, "Data1")


        Dim crystal As New CrystalReport1

        crystal.SetDataSource(DtSet.Tables("Data1"))
        CrystalReportViewer1.ReportSource = crystal
        CrystalReportViewer1.Refresh()

Fixed the seleccommand.connection but now I'm getting another exception
Object reference is not set to an instance on my Form4.con.open()

 Dim cmd As New OleDbCommand("Select * From Data1 Where DateFile = " & Form4.DataGridView1.SelectedRows(0).Cells(0).Value.ToString() & "", Form4.con)

        Dim adpt As New OleDbDataAdapter(cmd)
        Dim DtSet As New DataSet
        Form4.con.Open()
        adpt.Fill(DtSet, "Data1")


        Dim crystal As New CrystalReport1

        crystal.SetDataSource(DtSet.Tables("Data1"))
        CrystalReportViewer1.ReportSource = crystal
        CrystalReportViewer1.Refresh()
        Form4.con.Close()

fixed it
I just removed the con = nothing.
there will be another error about missing file
just put this in app.config and it's good
to go

<startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime version="v4.0"/>
  </startup>

Edited 3 Years Ago by jared.geli: edit

This question has already been answered. Start a new discussion instead.