Hi Armad
Sorry to keep bugging you. I have got the previous issues sorted out.
I am now trying to access a MS-Access database and collect data for one specific record.
Could you tell me how I should structure the code. On the code below I keep getting an error
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 42: myCommand.Parameters("@ID").Value = CStr(Request.Form("ID1"))
Line 43:
Line 44: worksheet.Cells.ImportFromDataReader(dataReader, True, 0, 0, True)
Line 45: dataReader = myCommand.ExecuteReader()
Line 46:
|
<%@ Page Language="VB" %>
<%@ Import Namespace="Microsoft.VisualBasic" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="Aspose.Words" %>
<%@ Import Namespace="Aspose.Cells" %>
<script runat="server">
Dim instance As OleDbCommand
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
'Instantiate an instance of license and set the license file through its path
Dim license As Aspose.Cells.License = New Aspose.Cells.License()
license.SetLicense("Aspose.Cells.lic")
Dim myCommand As OleDbCommand
Dim dataReader As System.Data.OleDb.OleDbDataReader = Nothing
'Instantiating a Workbook object
Dim workbook As Workbook = New Workbook()
'Adding a new worksheet to the Workbook object
workbook.Worksheets.Add()
'Obtaining the reference of the newly added worksheet by passing its sheet index
Dim worksheet As Worksheet = workbook.Worksheets(0)
'Adding a string value to the cell
worksheet.Cells("A1").PutValue("Test Report")
'Adding a date/time value to the cell
worksheet.Cells("D1").PutValue(DateTime.Now)
'Setting the display format of the date
worksheet.Cells("D1").Style.Number = 15
Dim connection As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("/fpdb/passliabcapture.mdb"))
connection.Open()
myCommand = New OleDbCommand("SELECT ID, Surname, RunDate, ActionDate, Description, TransType, Fin_TotalMnthPremium, Rejecteddebit, Cashdebitraised, Balance, EscapeFileNo FROM [trans] WHERE [ID] = @ID", connection)
'Importing the contents of the data reader to the worksheet
myCommand.Parameters.Add(New OleDbParameter("@ID", OleDbType.VarChar, 200))
myCommand.Parameters("@ID").Value = CStr(Request.Form("ID1"))
worksheet.Cells.ImportFromDataReader(dataReader, True, 0, 0, True)
dataReader = myCommand.ExecuteReader()
'Saving the Excel file
workbook.Save("Report.xls", FileFormatType.Default, Aspose.Cells.SaveType.OpenInExcel, Response)
End Sub