none
Attempted to read or write protected memory RRS feed

  • Question

  • Hi there

    I wrote an app that gets two excel sheets and puts them in two datattables for processing . since there a number of posible sheets the user has to define which kind of sheets he is feeding. this is achieved by selecting from two diffferent combos which are connected to two access tables.

    this is the code that connects to the combo (the other one is similar):

    DTRekhev.Clear()
      oddaRekhev = New OleDb.OleDbDataAdapter("select company,CompID from Companies order by company", conex)
      CBRekhev = New OleDb.OleDbCommandBuilder(oddaRekhev)
      oddaRekhev.Fill(DTRekhev)
      cmb_company.DataSource = DTRekhev
      cmb_company.DisplayMember = "company"
      cmb_company.ValueMember = "CompID"
      cmb_company.SelectedValue = "14"
      cmb_company.Text = "Choose company"
    

    after the user selects the combos he  selects the excel sheets:

    'Connects to Client Database
      
      Dim MyCommand As OleDb.OleDbDataAdapter
      Dim MyConnection As OleDb.OleDbConnection
    
      Try
       MyConnection = New OleDb.OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0; " & "data source=" & path & "; Extended Properties=Excel 8.0; ")
       ' Select the data from Sheet1 of the workbook.
       MyCommand = New OleDb.OleDbDataAdapter("select * from [" & sheet & "$] ", MyConnection)
    
       
      Catch ex As Exception
       
       MsgBox(ex.Message & " Source: " & ex.Source, MsgBoxStyle.Exclamation, ex.InnerException)
    
      End Try
      
     MyConnection.Close()
    

     

    here comes the problem:

    on some computers I installed the app everything runs fine. but on other computers on the last code is where I get the exception

    and if thats not weird enough listen to this:

    if I skip the combo selection part (say by typing the possibilities intsead of choosing them) then the app runs fine

    I've been struggling with this issue for weeks now

    please may someone have the great wisdom of knowing the solution

    Sincerly,


    Danielicy

    Danielicy
    Monday, July 4, 2011 7:08 AM

Answers

  • Extended Properties part of the connection string should be enclosed into additional double quotes. That could be the reason. If you look at the final connection string it should be something like

    "provider=Microsoft.Jet.OLEDB.4.0;data source=C:\MyFolder;"Extended Properties=Excel 8.0;""

     


    Val Mazur (MVP)

    http://www.xporttools.net

    Wednesday, July 6, 2011 10:39 AM
    Moderator

All replies