I am working on something for school as a final project before graduation.

I am using ASP for the website and VB as the back end to code.

I keep getting the error "Object reference not set to an instance of an object" and can't figure out what is wrong.

I am trying to using edit, update, cancel in the gridview for ASP

Imports System.Data.SqlClient


Partial Public Class CheckInOut
    Inherits System.Web.UI.Page
    Sub OnDSUpdatedHandler(ByVal source As Object, ByVal e As SqlDataSourceStatusEventArgs)
        
    End Sub 
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        

    End Sub
    Private Sub BindData()

    End Sub

    Protected Sub checkInOutGV_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles checkInOutGV.SelectedIndexChanged
        
    End Sub

    Protected Sub pullUpChildRecords_Click(ByVal sender As Object, ByVal e As EventArgs) Handles pullUpChildRecords.Click
        Dim connection As New SqlConnection("Data Source=Steven-PC;Integrated Security=True")
        Dim sqlstatement As String = "SELECT pickUpPerson FROM CheckInOut WHERE childID = " & childIDText.Text & ""
        Try
            Dim command As SqlCommand
            command = New SqlCommand(sqlstatement, connection)
        Catch
            checkInOutGV.Visible = False
        End Try
        'checkInOutGV.Visible = True

    End Sub
    Protected Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As GridViewCommandEventArgs)
    End Sub

    Protected Sub checkInOutGV_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs)
        Dim update = CType(Session("CHeckinOut"), DataTable)

        'Update the values.
        Dim row = checkInOutGV.Rows(e.RowIndex)
        update.Rows(row.DataItemIndex)("time_in") = (CType((row.Cells(1).Controls(0)), TextBox)).Text
        update.Rows(row.DataItemIndex)("time_out") = (CType((row.Cells(2).Controls(0)), TextBox)).Text
        update.Rows(row.DataItemIndex)("childName") = (CType((row.Cells(3).Controls(0)), CheckBox)).Checked
        update.Rows(row.DataItemIndex)("dropOffPerson") = (CType((row.Cells(4).Controls(0)), TextBox)).Text
        update.Rows(row.DataItemIndex)("pickUpPerson") = (CType((row.Cells(5).Controls(0)), TextBox)).Text
        update.Rows(row.DataItemIndex)("staffID") = (CType((row.Cells(6).Controls(0)), CheckBox)).Checked
        update.Rows(row.DataItemIndex)("childID") = (CType((row.Cells(7).Controls(0)), CheckBox)).Checked


        'Reset the edit index.
        checkInOutGV.EditIndex = -1

        'Bind data to the GridView control.
        BindData()
    End Sub

    Protected Sub checkInOutGV_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs)
        checkInOutGV.EditIndex = e.NewEditIndex

        BindData()
    End Sub

    Protected Sub childIDText_TextChanged(ByVal sender As Object, ByVal e As EventArgs) Handles childIDText.TextChanged

    End Sub

    Protected Sub checkInOutGV_RowCancelingEdit(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCancelEditEventArgs) Handles checkInOutGV.RowCancelingEdit
        checkInOutGV.EditIndex = -1

        BindData()
    End Sub

    Protected Sub checkInOutGV_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles checkInOutGV.PageIndexChanging
        checkInOutGV.PageIndex = e.NewPageIndex

        BindData()
    End Sub
End Class

That is what I have so far any help would be nice. Thanks. After this just need to get data to only show up to what I enter into text box. For some reason the data in the data grid loads up without me asking it to. I want it to be hidden till i enter say 2 into the textbox and only show the data from "childID" that is 2. This I can figure out in acouple hours really need help with the update though been trying to work on it and find it for days now. It is making my head hurt. Can only find people doing it in C#.

Thanks for any help.

Edited 5 Years Ago by StevenSchaffner: Had to add alittle more info.

Dumb question here steven, having looked at the code it makes my head hurt, why bother adding empty procedures and classes, tidy your code up and it may be that the server your trying to link to need two semi colons instead of one, seen it on a few college systems for internal addressing.

And as it is dimmed in a protected sub then it may not be available to outside routines, try calling the routine from inside the protected dim area.

It might help, sorry if it doesnt

See if this helps.

Protected Sub pullUpChildRecords_Click(ByVal sender As Object, ByVal e As EventArgs) Handles pullUpChildRecords.Click
        If Not childIDText.Text = "" Then
            MsgBox("Value cannot be empty in TextBox")
        Else
            '// run code here.
        End If
    End Sub

>>I keep getting the error "Object reference not set to an instance of an object" and can't figure out what is wrong.
On which line?

Edited 5 Years Ago by codeorder: n/a

This article has been dead for over six months. Start a new discussion instead.