Wrox Programmer Forums
|
VB.NET 2002/2003 Basics For coders who are new to Visual Basic, working in .NET versions 2002 or 2003 (1.0 and 1.1).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET 2002/2003 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 23rd, 2006, 04:25 PM
Registered User
 
Join Date: Jun 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Nosfe_X
Default Export data error

Hi guys

I need export data of access to excel pre-formated file, the final report have a partnumber and my excel's dataset have the same partnumber too. I need your help because i have a error "An unhandled exception of type 'System.NullReferenceException' ocurred in RECON_REPORT.exe
Aditional Information:Object Reference not set to an instance of an object."

I glad the help.

It is my code:

        Dim exopen As OpenFileDialog
        Dim exapp As Excel.Application
        Dim exbook As Excel.Workbook
        Dim exsheet As Excel.Worksheet
        Dim exfile As String

        exapp = New Excel.Application
        exopen = New OpenFileDialog

        exopen.Filter = "Open Microsoft Excel Document (HPDRIVESRECONXXXX.xls)|*.xls"
        exopen.Title = "Open Final Report HPDRIVESRECON"

        If exopen.ShowDialog = DialogResult.OK Then
            exfile = exopen.FileName
        End If
        exbook = exapp.Workbooks.Open(exfile)
        exapp.Visible = False
        exbook.Activate()

        With exbook
            exsheet = .Worksheets("May2006")

            info = 1
            Dim cols As Int32 = 7
            For Each ds2row In ds2excel.Tables("RECON_REPORT").Rows
                For info = 0 To ds2excel.Tables &_("RECON_REPORT").Rows.Count - 1
'here is my error
If ds2excel.Tables("MASTERS").Rows(info).Item 0).ToString =&_ exsheet.Range("B" & cols.ToString).Value Then
exsheet.Cells(cols, "S") = ds2row.Item &_ ("ERWC_IW")
exsheet.Range("S" & info.ToString).Value =&_ ds2row("ERWC_IW")
                        Exit For
                    End If
                Next info
                cols = cols + 1
            Next
        End With
        exbook.Save()
        exapp.Visible = True

 
Old June 26th, 2006, 12:22 PM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

I do believe that =& should be &=, and that you need a space before the following ‘_’

Plus, you have an asignation as a boolean. Essentially you have:
Code:
    If A += B Then
That’s not really meaningful.

In C, all statements return a value. This is not true in VB, and so is also probably not true in VB.NET.

Also this seems wrong:
Code:
    ds2excel.Tables("MASTERS").Rows(info).Item 0).ToString
That 0 all by itself after the word Item seems invalid. Did you mean .Item(0)? I think maybe you do, as it appears that you have unmatched parentheses.

Does this fix it?
 
Old June 27th, 2006, 12:06 PM
Registered User
 
Join Date: Jun 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Nosfe_X
Default

Thanks for all, i solved this problem with this code:

 System.Threading.Thread.CurrentThread.CurrentCultu re =&_ System.Globalization.CultureInfo.CreateSpecificCul ture("en-US")
  Dim exopen As OpenFileDialog
  Dim exapp As Excel.Application
  Dim exbook As Excel.Workbook
  Dim exsheet As Excel.Worksheet
  Dim exfile As String

  DataGrid1.DataSource = ds2excel.Tables("RECON_REPORT").DefaultView

  exapp = New Excel.Application
  exopen = New OpenFileDialog
  exopen.Filter = "Open Microsoft Excel Document &_(HPDRIVESRECON.xls)|*.xls"
  exopen.Title = "Open Final Report HPDRIVESRECON"

  If exopen.ShowDialog = DialogResult.OK Then
            exfile = exopen.FileName
        End If
        exbook = exapp.Workbooks.Open(exfile)
        exapp.Visible = False
        exbook.Activate()

        With exbook
            exsheet = .Worksheets("May2006")

            Dim cols As Integer = 0
 For cols = 7 To ds2excel.Tables("RECON_REPORT").Rows.Count - 1
   For info = 0 To ds2excel.Tables("RECON_REPORT").Rows.Count - 1

If exsheet.Range("B" & cols.ToString).Value = ds2excel.Tables("RECON_REPORT").Rows(info).Item("P ARTNUMBER").ToString Then

 exsheet.Range("S" & cols.ToString).Value = ds2excel.Tables("RECON_REPORT").Rows(info).Item("E RWC_IW").ToString()

Exit For
    End If
        Next info
           Next cols
            End With
        exbook.Save()
        exapp.Visible = True

Now my program no have problem with this process but freeze at time of execution.You have a method for better execution?






Similar Threads
Thread Thread Starter Forum Replies Last Post
Export to Excel (Data only) nikks9 ASP.NET 1.0 and 1.1 Professional 3 February 9th, 2011 05:01 AM
Export Data from xl to database show error. venkateswararaochaganti ASP.NET 2.0 Basics 0 November 3rd, 2008 04:37 AM
How to export data into Excel lily611 General .NET 8 January 11th, 2006 10:02 PM
Export data from data grid to excel pomoc VB.NET 2002/2003 Basics 0 December 16th, 2005 03:11 PM
Export data from data grid to Excel pomoc Visual Basic 2005 Basics 0 December 16th, 2005 02:56 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.