O
octeixeira
Guest
Hello to all.
I have the following code which works fine while getting the data from an Oracle database into the DataGridView1 object. Now i need to modify it in order to have the same data written into an Excel Worksheet. Can someone plese give an idea of how to do it?
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
Dim ConnectionString As String
ConnectionString = "User Id = APPS;Password = APPS; Data Source = PRODL"
Dim ConnectionOracle As New OracleConnection(ConnectionString)
ConnectionOracle.Open()
Dim OracleCommand As New OracleCommand
Dim dt As New DataTable
dt.Rows.Clear()
OracleCommand.Connection = ConnectionOracle
OracleCommand.CommandText = "SELECT v.VENDOR_NAME Fornecedor, i.INVOICE_NUM Factura, i.DOC_SEQUENCE_VALUE Arquivo, i.INVOICE_DATE Data, i.INVOICE_AMOUNT Valor, TRUNC(i.CREATION_DATE) Criada FROM AP_INVOICES_ALL i, FND_USER u, PO_VENDORS v WHERE u.USER_ID = i.CREATED_BY AND u.USER_ID = 2960 AND i.VENDOR_ID = v.VENDOR_ID AND TRUNC(i.CREATION_DATE) >=
1 AND TRUNC(i.CREATION_DATE) <=
2"
OracleCommand.CommandType = CommandType.Text
OracleCommand.Parameters.Add("P1", Me.DateTimePicker1.Value.Date)
OracleCommand.Parameters.Add("P2", Me.DateTimePicker2.Value.Date)
Dim DataReaderOracle As OracleDataReader
DataReaderOracle = OracleCommand.ExecuteReader()
If (DataReaderOracle.HasRows()) Then
dt.Load(DataReaderOracle)
AP_Result_Pesquisa.DataGridView1.DataSource = dt
AP_Result_Pesquisa.TextBox1.Text = "areis@tuiportugal.com"
AP_Result_Pesquisa.TextBox2.Text = AP_Result_Pesquisa.DataGridView1.Rows.Count
AP_Result_Pesquisa.Show()
Else
MsgBox("Não existem dados", vbOKOnly)
End If
DataReaderOracle.Close()
dt = Nothing
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Thanks a lot in advance for any kind help.
Octavio
Continue reading...
I have the following code which works fine while getting the data from an Oracle database into the DataGridView1 object. Now i need to modify it in order to have the same data written into an Excel Worksheet. Can someone plese give an idea of how to do it?
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
Dim ConnectionString As String
ConnectionString = "User Id = APPS;Password = APPS; Data Source = PRODL"
Dim ConnectionOracle As New OracleConnection(ConnectionString)
ConnectionOracle.Open()
Dim OracleCommand As New OracleCommand
Dim dt As New DataTable
dt.Rows.Clear()
OracleCommand.Connection = ConnectionOracle
OracleCommand.CommandText = "SELECT v.VENDOR_NAME Fornecedor, i.INVOICE_NUM Factura, i.DOC_SEQUENCE_VALUE Arquivo, i.INVOICE_DATE Data, i.INVOICE_AMOUNT Valor, TRUNC(i.CREATION_DATE) Criada FROM AP_INVOICES_ALL i, FND_USER u, PO_VENDORS v WHERE u.USER_ID = i.CREATED_BY AND u.USER_ID = 2960 AND i.VENDOR_ID = v.VENDOR_ID AND TRUNC(i.CREATION_DATE) >=


OracleCommand.CommandType = CommandType.Text
OracleCommand.Parameters.Add("P1", Me.DateTimePicker1.Value.Date)
OracleCommand.Parameters.Add("P2", Me.DateTimePicker2.Value.Date)
Dim DataReaderOracle As OracleDataReader
DataReaderOracle = OracleCommand.ExecuteReader()
If (DataReaderOracle.HasRows()) Then
dt.Load(DataReaderOracle)
AP_Result_Pesquisa.DataGridView1.DataSource = dt
AP_Result_Pesquisa.TextBox1.Text = "areis@tuiportugal.com"
AP_Result_Pesquisa.TextBox2.Text = AP_Result_Pesquisa.DataGridView1.Rows.Count
AP_Result_Pesquisa.Show()
Else
MsgBox("Não existem dados", vbOKOnly)
End If
DataReaderOracle.Close()
dt = Nothing
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Thanks a lot in advance for any kind help.
Octavio
Continue reading...