title: Object reference not set to an instance of an object. splitItems(0).toString
body: <p>i have this button which i add in row of data however, it give me error, can anyone help me out tell me why is the splitItems(0).ToString cause error, how should i get that value to store in the database</p>
  
  <pre><code>Protected Sub Button2_Click(sender As Object, e As System.EventArgs) Handles Button2.Click
  
          Dim rowIndex As Integer = 0
          Dim sc As New StringCollection()
          If ViewState("CurrentTable") IsNot Nothing Then
              Dim dtCurrentTable As DataTable = DirectCast(ViewState("CurrentTable"), DataTable)
              Dim drCurrentRow As DataRow = Nothing
              If dtCurrentTable.Rows.Count &lt; 10 Then
                  For i As Integer = 1 To dtCurrentTable.Rows.Count
                      'extract the TextBox values
  
                      Dim box5 As TextBox = DirectCast(Gridview3.Rows(rowIndex).Cells(1).FindControl("TextBox5"), TextBox)
  
                      'get the values here
  
                      Dim box6 As Date
                      box6 = Convert.ToDateTime(box5.Text)
                      Dim box7 As Date = Convert.ToDateTime(box5.Text)
  
  
  
                      sc.Add(box6)
  
  
  
                      rowIndex += 1
                  Next
  
                  InsertRecords(sc)
              End If
          Else
              '   lblMessage.Text = "Cannot save as there no information recorded"
              MsgBox("failed")
          End If
      End Sub
  
   Protected Sub InsertRecords(sc As StringCollection)
  
  
  
          Dim sb As New StringBuilder(String.Empty)
  
          Dim splitItems As String() = Nothing
  
          For Each item As String In sc
  
  
              If item.Contains(",") Then
                  splitItems = item.Split(",".ToCharArray())
  
  
  
  
              End If
          Next
  
          Try
  
              Dim myConn As New SqlConnection
              Dim myCmd As New SqlCommand
              myConn.ConnectionString = ConfigurationManager.ConnectionStrings("mydatabase").ConnectionString
              Dim cmd As String
              cmd = "Insert into Date values (@date) "
              myCmd.CommandText = cmd
              myCmd.CommandType = CommandType.Text
             //error found at this line splitItems(0).ToString()
              myCmd.Parameters.Add(New SqlParameter("@date", splitItems(0).ToString()))
  
  
              myCmd.Connection = myConn
              myConn.Open()
              myCmd.ExecuteNonQuery()
              myCmd.Dispose()
              myConn.Dispose()
  
              Page.ClientScript.RegisterClientScriptBlock(GetType(Page), "Script", "alert('Records Successfuly Saved!');", True)
          Catch ex As System.Data.SqlClient.SqlException
              Dim msg As String = "Insert Error:"
              msg += ex.Message
  
              Throw New Exception(msg)
          Finally
              conn.Close()
          End Try
      End Sub
  </code></pre>