Link to home
Create AccountLog in
Avatar of Millkind
MillkindFlag for Afghanistan

asked on

Object reference not set to an instance of an object. Probably Easy Answer.

This is throwing "Object reference not set to an instance of an object" for the line datarepairadapter.Fill(datapartset).

Public Class datarepair
    Public mainform As GCPOPTSselector
    Dim datapartset As DataSet
    Dim datarepairadapter As SqlDataAdapter
    Private Sub SHOW_DATA(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles datarepairshowdatabutton.Click
        Try
            drsc.Enabled = True
            datapartset = New DataSet
            Dim datapart As New SqlDataAdapter
            datapart = New SqlDataAdapter("Select * from data where DropOff between @sdate and @edate", mainform.conn)
            datapart.SelectCommand.Parameters.Add("@sdate", SqlDbType.Date).Value = drsd.Value.Date
            datapart.SelectCommand.Parameters.Add("@edate", SqlDbType.Date).Value = dred.Value.Date
            datarepairadapter.Fill(datapartset)
            datapartgrid.DataSource = datapartset.Tables(0)
            mainform.RecordUserAction("Data Repair", "Filling grid with data table from " & drsd.Value.Date & " to " & dred.Value.Date)
        Catch ex As Exception
            mainform.errorwrite("Data Repair" & ex.ToString)
        End Try
    End Sub

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Nevermind. @CodeCruiser has it.
Change datarepairadapter.Fill(datapartset) to datapart.Fill(datapartset)