Merging two XML files in to one dataset


Since so long back one of my best buddy Devang asked me that how can we merge two Datasets in one. In short, suppose you’ve two XML Files and you want to read them in different dataset. So, obviously they both will belong to two different data sets. But you would like to have both of them in a single dataset. How can you do it?
Before you see the solution code. Let’s see the problem by code
[sourcecode language=”csharp”]
private const string FILE1_PATH = "~/Books1.xml";
private const string FILE2_PATH = "~/Books2.xml";
protected void Page_Load(object sender, EventArgs e)
// Read First Xml
DataSet dataSet1 = new DataSet();
// Read Second Xml
DataSet dataSet2 = new DataSet();
// Merge — Will not work
// Read in Table — Will not work
// Merge DataSet2.Table in first dataset — WILL NOT WORK — DataTable already belongs to another DataSet.


When we try to use following line.
[sourcecode language=”csharp”]
// Merge DataSet2.Table in first dataset — WILL NOT WORK — DataTable already belongs to another DataSet.
It will throw following error:
DataTable already belongs to another DataSet.
System.ArgumentException was unhandled by user code
Message=”DataTable already belongs to another DataSet.”
at System.Data.DataTableCollection.BaseAdd(DataTable table)
at System.Data.DataTableCollection.Add(DataTable table)
at _Default.Page_Load(Object sender, EventArgs e) in c:\TestHarness\MergeTwoXmlFiles\Default.aspx.cs:line 35
at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)
at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)
at System.Web.UI.Control.OnLoad(EventArgs e)
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
Reason fort an error is dataset2’s Table number 0 can’t be added to dataset1’s tables collection as it is already in dataset2’s tables collection — Recall Reference types?
So, final solution is as below:
[sourcecode language=”csharp”]</pre>
// Remove table from second dataset
DataTable dt = dataSet2.Tables[0];
// and add it to first one
Happy Dataset Merging! 🙂

Adding Assembly in to GAC-Progrmmatically

How To Add Assembly in GAC(Global Assembly Cache) Programmatically?

In my last project I need to ad Assembly to GAC…you will tell go to Microsoft .Net Configuration tool and Add Assembly to GAC….i also know this i am not that much dump…But i need to add it programmatically….now you also have to think na???? But i have its solution so don’t worry just follow this Post..
First i think u know that what it requires to add an assembly to GAC..What??????You don’t…….no worries yaar Main Hoon na…
For Adding an Assembly to GAC…your assembly should have strong name…what???you don’t know how to make an assembly which contains strong name….i am going to be a Mad now you don’t know anything… anyways i will guide you to do that so no worries.
Just Have to follow 3 Steps:
Step 1: Open .NET Framework SDK Command Prompt. and Type sn- k <keyname>.snk
Strong NAme01
This will generate a Key at current path. In Above’s examples(C:\).
Step 2. Now Add this Strong name to your solution by right click on solution and Add an Existing Item and locate Key File.
Strng Name 02
Step 3: Now Open AssemblyInfo.CS/Vb file and add [assembly: AssemblyKeyFile(“key.snk”)] this line.
Strong name03
That’s it now your Assembly have a Strong name and it is ready to be add in GAC..
Its easy na????
Now my main Aim comes tht how to add assembly to GAC programmatically.
It is also easy.Just follow me.
1. Add Reference to System.Enterpriseservices.
2. It has Publish Class make its object:
Publish publish = new Publish();
3. And now you can Install it into using this:
publish.GacInstall(<Path of your Assembly to Add in GAC>);
you can show a openFileDialog to user from it user can select an Assembly and based on FilePath Property you can add it into GAC..and Magic it is going to be added in GAC..user will Be happy!!![and that’s what a developer i right?].
Just by following 3 Steps your assembly is in to it good na???
But there is one problem in it..can you guess what???No na..ok let me tell you.
See if Assembly dosen’t contains Strong Name than it will not show any error and not add it in to GAC Also..end user will not come in to know about it any time…so now what to do??? I have developed one Helper Class which will check that Assembly has strong name or not, user has permission to Add Assembly in to GAC etc.
So here is my Helper Class:
[sourcecode language=”csharp”]
<em><strong>public class Helper
public enum ErrorMessage
None, //NO ERROR
AssemblyNotFound, //Assembly can’t be found
AssemblyLoadError, //Error during loading assembly
NotCLRAssembly, //Specified Assembly is Not a CLR Assembly
NotAuthorized //Security Exception</strong></em>
<em><strong> } </strong></em>
<em><strong> public static ErrorMessage InstallAssembly(String assemblyPath)
if (String.IsNullOrEmpty(assemblyPath))
return ErrorMessage.AssemblyNotFound;
<em><strong>Assembly assembly = Assembly.ReflectionOnlyLoadFrom(assemblyPath);
byte[] pkey = assembly.GetName().GetPublicKeyToken();
if (pkey.Length == 0) return ErrorMessage.NotSignedAssembly;</strong></em>
catch (BadImageFormatException)
return ErrorMessage.NotCLRAssembly;
catch (FileLoadException)
return ErrorMessage.AssemblyLoadError;
catch (FileNotFoundException)
return ErrorMessage.AssemblyNotFound;
catch (SecurityException)
return ErrorMessage.NotAuthorized;
Publish publish = new Publish();</strong></em>
return ErrorMessage.None;
catch (SecurityException)
return ErrorMessage.NotAuthorized;
} </strong></em>
<span style="color: #ff00ff;"> }</span>
To use it:
[sourcecode language=”csharp”]
<em><strong> private bool InstallAssembly()
String AssemblyPath = assemblyofd.FileName;</strong></em>
<em><strong> OpenFileDialog assemblyofd = new OpenFileDialog();
bool installed = false;
if (!string.IsNullOrEmpty(AssemblyPath))
Helper.ErrorMessage ErrMsg = Helper.InstallAssembly(AssemblyPath);
case Helper.ErrorMessage.None:
//MessageBox.Show("The assembly you specify is successfully installed into the GAC", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
installed = true;
<em><strong> case Helper.ErrorMessage.AssemblyLoadError:
MessageBox.Show("Some problem occured During Loading an Assembly,Please Try Later", "Cannot Add Assembly", MessageBoxButtons.OK, MessageBoxIcon.Error);
installed = false;
case Helper.ErrorMessage.AssemblyNotFound:
MessageBox.Show("Sorry, Unable to Find Assembly", "Cannot Add Assembly", MessageBoxButtons.OK, MessageBoxIcon.Error);
installed = false;
case Helper.ErrorMessage.NotAuthorized:
MessageBox.Show("You are not authorized to install Assembly, please Contact your Administrator", "Cannot Add Assembly", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
installed = false;
case Helper.ErrorMessage.NotCLRAssembly:
MessageBox.Show("The assembly you specify is not a managed assembly", "Cannot Add Assembly", MessageBoxButtons.OK, MessageBoxIcon.Error);
installed = false;
case Helper.ErrorMessage.NotSignedAssembly:
MessageBox.Show("Unable to add the selcted assembly. The assembly must have a strong name (name,versioan and public key).", "Cannot Add Assembly", MessageBoxButtons.OK, MessageBoxIcon.Error);
installed = false;
case Helper.ErrorMessage.Unknown:
MessageBox.Show("Some problem occured during Installing Assembly", "Cannot Add Assembly", MessageBoxButtons.OK, MessageBoxIcon.Error);
installed = false;
return installed;
That’s it.
This will serve the Purpose.
Try it and let me know it works for you or not.
“If you do your best whatever happens will be for the best”.

There is no script engine for file extension “.vbs”


If you received an error saying There is no script engine for file extension “.vbs” then you are on right post 🙂


I tried doing this : regsvr32 %systemroot%\system32\vbscript.dll

But like you — for me too no luck 🙁

But finally following trick worked for me 🙂

1. Locate the file %windir%\inf\wsh.inf (inf is a hidden

2.right click and select “Install”.

Happy Coding!!

IE innerHTML – “Unknown runtime error”

Setting value of <div id=”divhtml”> using js like this :

document.getElementById(“divhtml”).innerHTML = “<form><input type=”text”>…</form>”;

it was giving me error..


oldDiv = document.getElementById(divhtml);
newDiv = document.createElement(oldDiv.tagName); =;
newDiv.className = oldDiv.className;
newDiv.innerHTML = “<form><input type=”text”>…</form>”;

oldDiv.parentNode.replaceChild(newDiv, oldDiv);

And it worked like a charm!!!!!!

Link :