Best way to Bulk Insert from a C# DataTable

If using SQL Server, SqlBulkCopy.WriteToServer(DataTable) SqlBulkCopy.WriteToServer Method (DataTable) Or also with SQL Server, you can write it to a .csv and use BULK INSERT BULK INSERT (Transact-SQL) If using MySQL, you could write it to a .csv and use LOAD DATA INFILE LOAD DATA INFILE Syntax If using Oracle, you can use the array binding … Read more

what’s the use of string.Clone()?

This is useful since string implements ICloneable, so you can create a copy of clones for a collection of ICloneable items. This is boring when the collection is of strings only, but it’s useful when the collection contains multiple types that implement ICloneable. As for copying a single string it has no use, since it … Read more

How to use Reflection to Invoke an Overloaded Method in .NET

You have to specify which method you want: class SomeType { void Foo(int size, string bar) { } void Foo() { } } SomeType obj = new SomeType(); // call with int and string arguments obj.GetType() .GetMethod(“Foo”, new Type[] { typeof(int), typeof(string) }) .Invoke(obj, new object[] { 42, “Hello” }); // call without arguments obj.GetType() … Read more

How to get all sections by name in the sectionGroup applicationSettings in .Net 2.0

Take a look at the ConfigurationManager.OpenExeConfiguration function to load in your configuration file. Then on the System.Configuration.Configuration class that you’ll get back from ConfigurationManager.OpenExeConfiguration you’ll want to look at the SectionGroups property. That’ll return a ConfigurationSectionGroupCollection in which you’ll find the applicationSettings section. In the ConfigurationSectionGroupCollection there will be a Sections property which contains the … Read more

“Could not load file or assembly System.Drawing or one of its dependencies” error on .Net 2.0, VS2010 and Windows 8

This is a bug. I have seen it too. It happens because your .resx file is pointing to 4.0.0.0 version of System.Drawing where one does not exist. To overcome this problem i usually edit the .resx in notepad to change 4.0.0.0 to 2.0.0.0. The bug is introduced by following the exact steps that you have … Read more

How does the “Using” statement translate from C# to VB?

Using has virtually the same syntax in VB as C#, assuming you’re using .NET 2.0 or later (which implies the VB.NET v8 compiler or later). Basically, just remove the braces and add a “End Using” Dim bitmap as New BitmapImage() Dim buffer As Byte() = GetHugeByteArrayFromExternalSource() Using stream As New MemoryStream(buffer, false) bitmap.BeginInit() bitmap.CacheOption = … Read more