DateTimePicker对象引用未设置为对象NullException的实例

时间:2018-03-22 14:28:20

标签: .net vb.net datetimepicker

我试图找到解决方案但尚未成功,我的程序将让用户从Oracle数据库获取数据到数据网格并让它们导出到Excel,但在尝试使用时一个datetimepicker用作我的查询中的值,调试器得到一个NullReferenceException错误,Object引用未设置为对象错误的实例。这是我的代码(我已经清除了安全性的连接数据)。

Imports System
Imports System.Collections.Generic
Imports System.Data
Imports Oracle.DataAccess.Client 'ODP.NET Oracle managed provider
Imports Oracle.DataAccess.Types
Imports System.IO
Imports System.Text.RegularExpressions
Imports System.Threading

Public Class frmReport2
 Dim rs As New Resizer
 Dim UpdateThread As Thread
 Dim UpdateThreadStart As New ThreadStart(AddressOf QueryDataBase)
 Dim CallDataBindToDataGrid As New MethodInvoker(AddressOf 
 Me.DataBindToDataGrid)
 Dim MyDataSet As DataSet
 Dim MyDataAdapter As OracleDataAdapter

Dim MyQueryString As String =
    "SELECT b.VEH_CODIGO_MAEXBIC AS AUTOBUS, a.STV_CAMARA AS CÁMARA, a.STV_FICHERO AS ARCHIVO," &
    "TO_CHAR(CAST(a.STV_INICIO AS DATE),'DD/MM/YYYY') AS FECHA_INICIO, TO_CHAR(CAST(a.STV_INICIO AS DATE),'HH24:MI:SS')" &
    "AS HORA_INICIO, TO_CHAR(CAST(a.STV_FIN AS DATE),'DD/MM/YYYY') AS FECHA_FIN, TO_CHAR(CAST(a.STV_FIN AS DATE),'HH24:MI:SS')" &
    "AS HORA_FIN FROM SAE_STATUS_VIDEO a INNER JOIN CVI_VEHICULOS b ON a.STV_STE_ID = b.VEH_ID" &
    "WHERE TO_CHAR(CAST(a.STV_INICIO AS DATE),'DD/MM/YYYY') BETWEEN '" + DateFchInicio.Value + "' AND '" + DateFchFin.Value + "' " &
    "AND TO_CHAR(CAST(a.STV_INICIO As Date),'HH24:MI:SS') BETWEEN '" + DateHrInicio.Value + "' AND '" + DateHrFin.Value + "' ORDER BY STV_INICIO DESC;"

Dim MyConnection As New OracleConnection("")
Private Sub frmReport2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    Control.CheckForIllegalCrossThreadCalls = False
    rs.FindAllControls(Me)
    TStripStLabel.Text = "Listo"

End Sub

Private Sub frmReport2_Resize(sender As Object, e As EventArgs) Handles Me.Resize
    rs.ResizeAllControls(Me)
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles BtnBuscar.Click
    UpdateThread = New Thread(UpdateThreadStart)
    UpdateThread.IsBackground = True
    UpdateThread.Name = "Update Thread"
    UpdateThread.Start()


End Sub

' Sub routine that is to be executed on Form's thread.
Public Sub DataBindToDataGrid()
    DGVOra.DataSource = MyDataSet
    DGVOra.DataMember = "SAE_STATUS_VIDEO"
    'MyDataAdapter = Nothing
    'MyDataSet = Nothing
End Sub

' Sub routine used by the background thread to query database.
Public Sub QueryDataBase()
    MyDataSet = New DataSet()
    MyConnection.Open()
    Dim cmd As New OracleCommand(MyQueryString, MyConnection)
    MyDataAdapter = New OracleDataAdapter(cmd)
    'LblStatus.Text = "Buscando Información"
    TStripStLabel.Text = "Buscando Información"
    MyDataAdapter.Fill(MyDataSet, "SAE_STATUS_VIDEO")
    MyConnection.Close()
    'LblStatus.Text = "Operación finalizada"
    TStripStLabel.Text = "Operación Finalizada"
    ' Make asynchronous function call to Form's thread.
    Me.BeginInvoke(CallDataBindToDataGrid)
End Sub

Private Sub SalirToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles SalirToolStripMenuItem.Click
    Dim result As DialogResult = MessageBox.Show("Estas seguro que deseas salir?", "Desea Salir?", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
    If result = DialogResult.Yes Then
        Application.Exit()
    End If
    'MsgBox("Estas seguro que deseas salir?", MsgBoxStyle.OkCancel, "Desea Salir?", Msg) = MsgBoxResult.Ok Then
 End Sub
End Class

1 个答案:

答案 0 :(得分:0)

将查询字符串移动到其他子