none
Why Am I getting this message when creating a dataset. RRS feed

  • Question

  •  

    Hi;

     

    I have connected to an excel file and I want to read the contents into a dataset.

     

    I get an error at this point in the code,  da2.Fill(ds2, "Addresses"when I try to run the application

     

     

    System.Data.Odbc.OdbcException was unhandled
      ErrorCode=-2146232009
      Message="ERROR [42S02] [Microsoft][ODBC Excel Driver] The Microsoft Jet database engine could not find the object 'xls'.  Make sure the object exists and that you spell its name and the path name correctly."
      Source="odbcjt32.dll"
      StackTrace:
           at System.Data.Odbc.OdbcConnection.HandleError(OdbcHandle hrHandle, RetCode retcode)
           at System.Data.Odbc.OdbcCommand.ExecuteReaderObject(CommandBehavior behavior, String method, Boolean needReader, Object[] methodArguments, SQL_API odbcApiMethod)
           at System.Data.Odbc.OdbcCommand.ExecuteReaderObject(CommandBehavior behavior, String method, Boolean needReader)
           at System.Data.Odbc.OdbcCommand.ExecuteReader(CommandBehavior behavior)
           at System.Data.Odbc.OdbcCommand.ExecuteDbDataReader(CommandBehavior behavior)
           at System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior)
           at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
           at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
           at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, String srcTable)
           at Verimove2008.Form3.Load_ExlDat() in C:\Documents and Settings\k4gp5\My Documents\Visual Studio 2005\Projects\Verimove2008\Verimove2008\Form3.vb:line 48
           at Verimove2008.Form3.Form3_Load(Object sender, EventArgs e) in C:\Documents and Settings\k4gp5\My Documents\Visual Studio 2005\Projects\Verimove2008\Verimove2008\Form3.vb:line 35
           at System.EventHandler.Invoke(Object sender, EventArgs e)
           at System.Windows.Forms.Form.OnLoad(EventArgs e)
           at System.Windows.Forms.Form.OnCreateControl()
           at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
           at System.Windows.Forms.Control.CreateControl()
           at System.Windows.Forms.Control.WmShowWindow(Message& m)
           at System.Windows.Forms.Control.WndProc(Message& m)
           at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
           at System.Windows.Forms.ContainerControl.WndProc(Message& m)
           at System.Windows.Forms.Form.WmShowWindow(Message& m)
           at System.Windows.Forms.Form.WndProc(Message& m)
           at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
           at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
           at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
           at System.Windows.Forms.SafeNativeMethods.ShowWindow(HandleRef hWnd, Int32 nCmdShow)
           at System.Windows.Forms.Control.SetVisibleCore(Boolean value)
           at System.Windows.Forms.Form.SetVisibleCore(Boolean value)
           at System.Windows.Forms.Control.set_Visible(Boolean value)
           at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
           at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
           at System.Windows.Forms.Application.Run(ApplicationContext context)
           at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
           at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
           at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
           at Verimove2008.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
           at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
           at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
           at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
           at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
           at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
           at System.Threading.ThreadHelper.ThreadStart()
    ========================================================================================

     

    Has anyone had this error  before ?

     

    Here is the complete code :

     

     

    Dim conStr2 As String = _

    "Driver={Microsoft Excel Driver (*.xls)};DBQ=c:\site\"

    Dim conn2 As OdbcConnection = New OdbcConnection(conStr2)

    ' Try

    conn2.Open()

    Dim da2 As OdbcDataAdapter = New OdbcDataAdapter _

    ("Select column1, column2, column3, col4, col5, col6, col7 from Test1.xls", conn2)

    Dim ds2 As DataSet = New DataSet()

    da2.Fill(ds2, "Addresses")

    DataGridView2.DataSource = ds2.DefaultViewManager

    conn2.Close()

    conn2.Dispose()

     

    Thanks for any insights.

    Wednesday, October 1, 2008 9:53 PM

Answers

  • This is an error message comming from the Odbc Jet provider.

    You'd get the same problem if you just did this

      Dim conStr2 As String = "Driver={Microsoft Excel Driver (*.xls)};DBQ=c:\site\"

      Dim conn2 As OdbcConnection = New OdbcConnection(conStr2)

      Dim cmd as New OdbcCommand("Select column1, column2, column3, col4, col5, col6, col7 from Test1.xls", conn2)

      Dim reader  = cmd.ExecuteReader()

      reader.Close()

     

    Try

      Dim conStr2 As String = "Driver={Microsoft Excel Driver (*.xls)};DBQ=c:\site\Test1.xls"

      Dim da2 As OdbcDataAdapter = New OdbcDataAdapter ("Select column1, column2, column3, col4, col5, col6, col7 from Test1", conn2)

    Wednesday, October 1, 2008 11:27 PM
    Moderator