请帮助,我尝试制作一个程序,让用户从Oracle数据库获取数据到datagridview并让它们导出到Excel,但是在获取数据时,DGV只显示一列名称和一个空行。我从Oracle View获取数据,我知道这些表有数据。 这是我的代码(我已经清除了安全性的连接数据)。
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 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 = "AUX_STATUS"
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 MyQueryString As String = "SELECT * FROM AUX_STATUS WHERE FECHA_INICIO " &
"BETWEEN '" + DateFchInicio.Value + "' AND '" + DateFchFin.Value + "' AND HORA_INICIO BETWEEN '" + DateHrInicio.Value + "' AND '" + DateHrFin.Value + "'"
Dim cmd As New OracleCommand(MyQueryString, MyConnection)
MyDataAdapter = New OracleDataAdapter(cmd)
'LblStatus.Text = "Buscando Información"
TStripStLabel.Text = "Buscando Información"
MyDataAdapter.Fill(MyDataSet, "AUX_STATUS")
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
答案 0 :(得分:0)
由于我只需要Date和每个DateTimePicker,我将其添加到MyQueryString
上的每个值:
DateFchInicio.Value.ToShortDateString
DateFchFin.Value.ToShortDateString
DateHrInicio.Value.ToLongTimeString
DateHrFin.Value.ToLongTimeString