|
-
Jan 20th, 2006, 08:15 PM
#1
Thread Starter
Hyperactive Member
[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:
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim ExcelApp As Microsoft.Office.Interop.Excel.Application = GetObject("", "Excel.Application")
Dim ExcelWorkbook As Microsoft.Office.Interop.Excel.Workbook
Dim ExcelWorksheet As Microsoft.Office.Interop.Excel.Worksheet
Dim ExcelRange As Microsoft.Office.Interop.Excel.Range
Dim ColumnData As String
Dim ADOConn As New ADODB.Connection
Dim ADOComm As New ADODB.Command
Dim ADOParam As New ADODB.Parameter
Dim ADORec As New ADODB.Recordset
Dim EmployeeCounter As Integer
Dim EmployeeMaxCounter As Integer
Label1.Visible = True
EmployeeCounter = 1
EmployeeMaxCounter = 42
ExcelWorkbook = ExcelApp.Workbooks.Open("C:\Transglobal Knowledge\Employ Pro 0.0.1\as of January 2006.xls")
ExcelWorksheet = ExcelWorkbook.Worksheets("Sheet1")
ADOConn.ConnectionString = "Provider=SQLOLEDB.1;Password=cons0l;Persist Security Info=True;User ID=sa;Initial Catalog=Employees;Data Source=MNLBS001"
ADOConn.Open()
For EmployeeCounter = 1 To EmployeeMaxCounter
ADOParam = ADOComm.CreateParameter("@Fullname", ADODB.DataTypeEnum.adVarChar, ADODB.ParameterDirectionEnum.adParamInput, 50)
ADOComm.CommandText = "[NewConvEmp]"
ADOComm.CommandType = ADODB.CommandTypeEnum.adCmdStoredProc
ADOComm.ActiveConnection = ADOConn
ExcelRange = ExcelWorksheet.Cells(16 + EmployeeCounter, 2)
ColumnData = ExcelRange.Text
ADOParam.Value = ColumnData
ADOComm.Parameters.Append(ADOParam)
ADORec = ADOComm.Execute()
ProgressBar1.Increment(100 / (EmployeeMaxCounter - (EmployeeCounter + 1)))
ADOComm.Parameters.Refresh()
Next
ADOConn.Close()
ExcelWorkbook.Close()
ExcelApp.Quit()
End Sub
-
Jan 20th, 2006, 08:19 PM
#2
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Jan 20th, 2006, 08:28 PM
#3
Thread Starter
Hyperactive Member
Re: A weird Excel problem
 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?
-
Jan 20th, 2006, 08:37 PM
#4
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Jan 20th, 2006, 08:42 PM
#5
Thread Starter
Hyperactive Member
-
Jan 20th, 2006, 08:46 PM
#6
Thread Starter
Hyperactive Member
Re: A weird Excel problem
 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.
-
Jan 20th, 2006, 09:15 PM
#7
Thread Starter
Hyperactive Member
Re: A weird Excel problem
How do I use ADO .NET to connect to an Excel worksheet?
-
Jan 20th, 2006, 10:02 PM
#8
Thread Starter
Hyperactive Member
Re: A weird Excel problem
-
Jan 20th, 2006, 11:28 PM
#9
Thread Starter
Hyperactive Member
Re: A weird Excel problem
-
Jan 21st, 2006, 06:33 AM
#10
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Jan 21st, 2006, 06:47 AM
#11
Re: A weird Excel problem
What code are you using now?
-
Jan 22nd, 2006, 09:02 PM
#12
Thread Starter
Hyperactive Member
Re: A weird Excel problem
 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.
-
Jan 22nd, 2006, 09:51 PM
#13
Re: A weird Excel problem
 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.
-
Jan 22nd, 2006, 10:06 PM
#14
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|