Results 1 to 14 of 14

Thread: [RESOLVED] A weird Excel problem

  1. #1

    Thread Starter
    Hyperactive Member tommygrayson's Avatar
    Join Date
    Aug 2005
    Location
    In my Nissan Silvia
    Posts
    433

    Resolved [RESOLVED] A weird Excel problem

    Help!!! Help!!! Help!!! I always have this error whenever I transfer Excel data to SQL.

    An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in adodb.dll
    Every time I run this code

    VB Code:
    1. Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.         Dim ExcelApp As Microsoft.Office.Interop.Excel.Application = GetObject("", "Excel.Application")
    3.         Dim ExcelWorkbook As Microsoft.Office.Interop.Excel.Workbook
    4.         Dim ExcelWorksheet As Microsoft.Office.Interop.Excel.Worksheet
    5.         Dim ExcelRange As Microsoft.Office.Interop.Excel.Range
    6.         Dim ColumnData As String
    7.         Dim ADOConn As New ADODB.Connection
    8.         Dim ADOComm As New ADODB.Command
    9.         Dim ADOParam As New ADODB.Parameter
    10.         Dim ADORec As New ADODB.Recordset
    11.         Dim EmployeeCounter As Integer
    12.         Dim EmployeeMaxCounter As Integer
    13.         Label1.Visible = True
    14.         EmployeeCounter = 1
    15.         EmployeeMaxCounter = 42
    16.         ExcelWorkbook = ExcelApp.Workbooks.Open("C:\Transglobal Knowledge\Employ Pro 0.0.1\as of January 2006.xls")
    17.         ExcelWorksheet = ExcelWorkbook.Worksheets("Sheet1")
    18.         ADOConn.ConnectionString = "Provider=SQLOLEDB.1;Password=cons0l;Persist Security Info=True;User ID=sa;Initial Catalog=Employees;Data Source=MNLBS001"
    19.         ADOConn.Open()
    20.         For EmployeeCounter = 1 To EmployeeMaxCounter
    21.             ADOParam = ADOComm.CreateParameter("@Fullname", ADODB.DataTypeEnum.adVarChar, ADODB.ParameterDirectionEnum.adParamInput, 50)
    22.             ADOComm.CommandText = "[NewConvEmp]"
    23.             ADOComm.CommandType = ADODB.CommandTypeEnum.adCmdStoredProc
    24.             ADOComm.ActiveConnection = ADOConn
    25.             ExcelRange = ExcelWorksheet.Cells(16 + EmployeeCounter, 2)
    26.             ColumnData = ExcelRange.Text
    27.             ADOParam.Value = ColumnData
    28.             ADOComm.Parameters.Append(ADOParam)
    29.             ADORec = ADOComm.Execute()
    30.             ProgressBar1.Increment(100 / (EmployeeMaxCounter - (EmployeeCounter + 1)))
    31.             ADOComm.Parameters.Refresh()
    32.         Next
    33.         ADOConn.Close()
    34.         ExcelWorkbook.Close()
    35.         ExcelApp.Quit()
    36. End Sub

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: A weird Excel problem

    Looks like your using the ADODB instead of ADO.NET for starters. Then you should use a Try Catch to trap the error being generated from the data access code.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    Hyperactive Member tommygrayson's Avatar
    Join Date
    Aug 2005
    Location
    In my Nissan Silvia
    Posts
    433

    Question Re: A weird Excel problem

    Quote Originally Posted by RobDog888
    Looks like your using the ADODB instead of ADO.NET for starters. Then you should use a Try Catch to trap the error being generated from the data access code.
    Hmmm... good point. I will "try" that.

    I have another question. Is ADO .NET better than ADODB when in comes to transferring Excel data to SQL?

    Does data adapter objects use ADO .NET?

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: A weird Excel problem

    Yes, ADO.NET is better then using the old ADO in general.

    A data adapter is part of ado.net.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  5. #5

    Thread Starter
    Hyperactive Member tommygrayson's Avatar
    Join Date
    Aug 2005
    Location
    In my Nissan Silvia
    Posts
    433

    Exclamation Re: A weird Excel problem

    Now I'm getting somewhere. I will not use ADODB at this state. I will try to use the Data Adapter.

    I always love ADODB but in this case I have no choice but to change it to ADO .NET.

  6. #6

    Thread Starter
    Hyperactive Member tommygrayson's Avatar
    Join Date
    Aug 2005
    Location
    In my Nissan Silvia
    Posts
    433

    Question Re: A weird Excel problem

    Quote Originally Posted by RobDog888
    Looks like your using the ADODB instead of ADO.NET for starters. Then you should use a Try Catch to trap the error being generated from the data access code.
    Now I'm getting somewhere. The error has generated a more clear message.

    Muti-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work has done.
    What does the error message mean?
    Last edited by tommygrayson; Jan 20th, 2006 at 08:50 PM.

  7. #7

    Thread Starter
    Hyperactive Member tommygrayson's Avatar
    Join Date
    Aug 2005
    Location
    In my Nissan Silvia
    Posts
    433

    Question Re: A weird Excel problem

    How do I use ADO .NET to connect to an Excel worksheet?

  8. #8

    Thread Starter
    Hyperactive Member tommygrayson's Avatar
    Join Date
    Aug 2005
    Location
    In my Nissan Silvia
    Posts
    433

    Re: A weird Excel problem

    Can anyone help me here?

  9. #9

    Thread Starter
    Hyperactive Member tommygrayson's Avatar
    Join Date
    Aug 2005
    Location
    In my Nissan Silvia
    Posts
    433

    Re: A weird Excel problem

    Anyone?

  10. #10
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: A weird Excel problem

    There are several causes for this error. Did you search the hlpe file for the error message?

    Step through your code and check your values and see what its actually doing.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  11. #11
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: A weird Excel problem

    What code are you using now?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  12. #12

    Thread Starter
    Hyperactive Member tommygrayson's Avatar
    Join Date
    Aug 2005
    Location
    In my Nissan Silvia
    Posts
    433

    Talking Re: A weird Excel problem

    Quote Originally Posted by RobDog888
    Yes, ADO.NET is better then using the old ADO in general.

    A data adapter is part of ado.net.
    I did followed your advice and it worked. Using the data adapter is much more easier than what I use. Thanks.

    I'll rate your post for that and Jmchilhinney's for responding.

  13. #13
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: A weird Excel problem

    Quote Originally Posted by tommygrayson
    I did followed your advice and it worked. Using the data adapter is much more easier than what I use. Thanks.

    I'll rate your post for that and Jmchilhinney's for responding.
    I don't mean to sound ungrateful but I'd suggest not rating posts just for responding. By all means rate posts that are genuinely helpful, but any old idiot can respond, as evidenced by the fact that I responded to this thread.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  14. #14
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: [RESOLVED] A weird Excel problem

    Maybe he was wanting to give a -ve rating Jk
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width