Answered by:
CreateObject equivalent function in c#

Question
-
What's the C# equivalent to the VB 'CreateObject' function.I want to do this for using SQLXMLBulkLoad
Here's the VB code I want to convert.
set objBL = CreateObject("SQLXMLBulkLoad.SQLXMLBulkload.3.0")
objBL.Execute "SampleSchema.xml", "SampleXMLData.xml"
Thanks for your help
SaiFriday, September 29, 2006 4:09 PM
Answers
-
Probably this is what you need
SQLXMLBULKLOADLib.SQLXMLBulkLoad3Class objXBL = new SQLXMLBULKLOADLib.SQLXMLBulkLoad3Class();
objXBL.ConnectionString = "Provider=sqloledb;server=server;database=db;uid=id;pwd=password";
objXBL.ErrorLogFile = "SQLXML3Books.errlog";
objXBL.KeepIdentity = false;
objXBL.Execute("Books.xsd", "Books1.xml");Friday, September 29, 2006 5:03 PM
All replies
-
Probably this is what you need
SQLXMLBULKLOADLib.SQLXMLBulkLoad3Class objXBL = new SQLXMLBULKLOADLib.SQLXMLBulkLoad3Class();
objXBL.ConnectionString = "Provider=sqloledb;server=server;database=db;uid=id;pwd=password";
objXBL.ErrorLogFile = "SQLXML3Books.errlog";
objXBL.KeepIdentity = false;
objXBL.Execute("Books.xsd", "Books1.xml");Friday, September 29, 2006 5:03 PM -
If you can't early bind it as the other poster recommends, the equivalent late binding code in C# is:
System.Type objBLType = System.Type.GetTypeFromProgID("SQLXMLBulkLoad.SQLXMLBulkload.3.0");
David Anton
object objBL = System.Activator.CreateInstance(objBLType);
objBLType.InvokeMember("Execute", System.Reflection.BindingFlags.InvokeMethod, null, objBL, new object[] {"SampleSchema.xml", "SampleXMLData.xml"});
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C# to C++ converter, VB to C++ converter
Instant Python: VB to Python converter
- Proposed as answer by Vijay R Tuesday, December 15, 2009 4:57 PM
Friday, September 29, 2006 11:42 PM -
Hi,
Thanks for your reply.
Your given solutions working pefectly.
Thanks
surya
Sunday, October 1, 2006 3:21 PM -
Hi,
I have some similar scenarios.
Quick question on this.
1. David, Why can't we early bind ? is it only for this dll or for any late binding scenario?2. Surya, Which solution worked for you?
Vij
Vijay RTuesday, September 1, 2009 5:11 PM -
The code I provided (many years ago) is not a direct equivalent.
The problem is that "CreateObject" is for creating instances of COM components, while the .NET reflection code I provided is strictly for calling methods of .NET assemblies via reflection.
In general, you should simply set a reference to the appropriate assembly and call the methods directly instead of via reflection.
Convert between VB, C#, C++, & Java (http://www.tangiblesoftwaresolutions.com)Wednesday, September 2, 2009 12:22 AM -
Hi David,
Thanks for the reply.
1. So does it mean that we can't use reflection to call methods of COM dll's (that is non .net assemblies)
2. does it mean that there is no direct equivalent in .Net for the 'CreateObject'
I understand that we can set a reference to the COM assembly in an .NET project, which would use the interop libraries, right?
Regards
Vijay R
Vijay RSunday, September 6, 2009 9:46 PM -
1. Correct
2. There is an equivalent: VisualBasic.Interaction.CreateObject. This is in the .NET assembly 'VisualBasic.dll'.
Once you have the interop assembly, I suppose there's no reason why you couldn't use reflection on it.
Convert between VB, C#, C++, & Java (http://www.tangiblesoftwaresolutions.com)- Proposed as answer by RatZzz Thursday, May 6, 2010 1:54 PM
Sunday, September 6, 2009 9:57 PM -
Hi All,
I am facing a similar kind of issue when coverting a the below piece of code from VB to C#
Dim lngMovedMessages As Long
Dim objMessageMover As COMSVCSLib.MessageMover
objMessageMover = CreateObject("QC.MessageMover")
objMessageMover.SourcePath = ".\\private$\\poisonedecomail"
objMessageMover.DestPath = ".\\private$\\ecomail"
lngMovedMessages = objMessageMover.MoveMessages
Can you please let me know equivalent of C# code for the above.
Thanks in Advance
-Raj
Thursday, May 6, 2010 1:37 PM