Click here to Skip to main content
15,887,596 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: Excel Data to Sql Database Pin
DrukenProgrammer9-Sep-08 9:31
DrukenProgrammer9-Sep-08 9:31 
GeneralRe: Excel Data to Sql Database Pin
Wendelius9-Sep-08 9:36
mentorWendelius9-Sep-08 9:36 
Question[Message Deleted] Pin
Rafone9-Sep-08 6:51
Rafone9-Sep-08 6:51 
AnswerRe: Arrays in VB Pin
Gregory Gadow9-Sep-08 7:41
Gregory Gadow9-Sep-08 7:41 
AnswerRe: Arrays in VB Pin
Rafone9-Sep-08 8:35
Rafone9-Sep-08 8:35 
GeneralRe: Arrays in VB Pin
Gregory Gadow9-Sep-08 12:03
Gregory Gadow9-Sep-08 12:03 
AnswerRe: Arrays in VB Pin
Rafone9-Sep-08 12:03
Rafone9-Sep-08 12:03 
QuestionImporting XLS file to DataTable Pin
Codemonkey859-Sep-08 5:10
Codemonkey859-Sep-08 5:10 
What I want to do for my company is turn our price book into a desktop application. I figured I could use an external file for the price data, for future editing purposes. I've been trying to do this in different ways for a while now, and it's sort of frustrating (this is my first real exposure to database programming and the like).

So I'm trying to read an Excel File into a DataTable. I have a sub going, but for some reason I keep getting a null reference exception:

System.NullReferenceException was unhandled
Message="Object reference not set to an instance of an object."

Private Sub ReadExcelData()
    'Try

    xlBook = GetObject("C:\Documents and Settings\Administrator.OFFICE2\Desktop\Michael\All_Item_Prices_2008.xls")
    Dim xlsSheet As Excel.Worksheet = xlBook.Worksheets(1)

    xlBook.Application.Visible = True
    xlBook.Windows(1).Visible = True
    xlBook.Application.WindowState = Excel.XlWindowState.xlMinimized

    Dim irow As Integer = 1
    Dim icol As Integer = 1

    'DataTable:
    '104 Rows
    '91 Columns icol irow

    'For icol = 1 To 91

    'xlsSheet.Cells(ROW, COLUMN).value
    MsgBox(xlsSheet.Cells(1, icol).Value.ToString)
    If xlsSheet.Cells(1, icol).Value <> Nothing Then
        New_Column = New DataColumn _
        (xlsSheet.Cells(1, icol).Value.ToString)
    Else
        New_Column = New DataColumn("FILLER " & icol)
    End If
    '*************************************************
    'NULL REFERENCE HAPPENS HERE
    ItemDataTable.Columns.Add(New_Column)
    'NULL REFERENCE HAPPENS HERE
    '*************************************************
    'For irow = 1 To 104
    'MsgBox(xlsSheet.Cells(irow, icol).Value)
    'ItemDataTable.Rows.Add = xlsSheet.Cells(irow, icol).Value.ToString
    New_Row = ItemTable.NewRow
    New_Row.Item(icol) = xlsSheet.Cells(irow, icol).Value.ToString
    'Next
    'Next

   'Catch
    'End Try
End Sub


If someone can tell me either what I'm doing wrong, or knows a better way (I have all of the prices and stuff saved as an Excel spreadsheet), please let me know. I would really appreciate it!

As I sit here, I contemplate the last words of Socrates: "I drank what?".

Pokémon Pearl Friend Code: 4554-2418-6836

AnswerRe: Importing XLS file to DataTable Pin
dan!sh 9-Sep-08 5:30
professional dan!sh 9-Sep-08 5:30 
GeneralRe: Importing XLS file to DataTable Pin
Codemonkey859-Sep-08 5:36
Codemonkey859-Sep-08 5:36 
GeneralRe: Importing XLS file to DataTable Pin
dan!sh 9-Sep-08 5:48
professional dan!sh 9-Sep-08 5:48 
GeneralRe: Importing XLS file to DataTable Pin
Codemonkey859-Sep-08 6:20
Codemonkey859-Sep-08 6:20 
GeneralRe: Importing XLS file to DataTable Pin
dan!sh 9-Sep-08 9:13
professional dan!sh 9-Sep-08 9:13 
GeneralRe: Importing XLS file to DataTable Pin
Codemonkey859-Sep-08 9:23
Codemonkey859-Sep-08 9:23 
AnswerRe: Importing XLS file to DataTable Pin
DrukenProgrammer9-Sep-08 8:58
DrukenProgrammer9-Sep-08 8:58 
GeneralRe: Importing XLS file to DataTable Pin
Codemonkey859-Sep-08 9:05
Codemonkey859-Sep-08 9:05 
GeneralRe: Importing XLS file to DataTable Pin
DrukenProgrammer9-Sep-08 9:12
DrukenProgrammer9-Sep-08 9:12 
GeneralRe: Importing XLS file to DataTable Pin
Codemonkey859-Sep-08 9:23
Codemonkey859-Sep-08 9:23 
GeneralRe: Importing XLS file to DataTable Pin
DrukenProgrammer9-Sep-08 9:34
DrukenProgrammer9-Sep-08 9:34 
GeneralRe: Importing XLS file to DataTable Pin
Codemonkey859-Sep-08 9:43
Codemonkey859-Sep-08 9:43 
Questionform name as a property of a custom control Pin
Randana9-Sep-08 4:38
Randana9-Sep-08 4:38 
AnswerRe: form name as a property of a custom control Pin
Manas Bhardwaj9-Sep-08 4:40
professionalManas Bhardwaj9-Sep-08 4:40 
GeneralRe: form name as a property of a custom control Pin
Randana9-Sep-08 4:45
Randana9-Sep-08 4:45 
AnswerWhy just the form name? Pin
Gregory Gadow9-Sep-08 8:05
Gregory Gadow9-Sep-08 8:05 
QuestionCreate a Semi Background Transparant Form Pin
pdnet9-Sep-08 3:58
pdnet9-Sep-08 3:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.