Guies I solved this quetion ..........
and i think this is the fastest way
DataSet ds1 = new DataSet("XML data1");
ds1.EnforceConstraints = false;
ds1.ReadXml(@"<XML file>");
try
{
SqlConnection conn = new SqlConnection("Server=localhost;Initial Catalog= XML_data;Trusted_Connection=True;");
conn.Open();
foreach (DataTable dt in ds1.Tables)
{
string exists = null;
try
{
SqlCommand cmd = new SqlCommand("SELECT * FROM sysobjects where name = '" + dt.TableName + "'", conn);
exists = cmd.ExecuteScalar().ToString();
}catch (Exception exce)
{
exists = null;
}
Console.WriteLine("Bulk Insert Started table:" + dt.TableName);
SqlBulkCopy bulk = new SqlBulkCopy(conn);
bulk.DestinationTableName = "[" + dt.TableName + "]";
foreach (DataColumn dc in dt.Columns)
{
bulk.ColumnMappings.Add(dc.ColumnName, dc.ColumnName);
string type = "";
typemappings.TryGetValue(dc.DataType.FullName.Split('.')[1], out type);
if (type == null)
type = "varchar(255)";
if (exists == null)
{
SqlCommand createtable = new SqlCommand("CREATE TABLE [" + dt.TableName + "] ([" + dc.ColumnName + "] " + type + ")", conn);
createtable.ExecuteNonQuery();
exists = dt.TableName;
}
else
{
try
{
SqlCommand addcolumn = new SqlCommand("ALTER TABLE [" + dt.TableName + "] ADD [" + dc.ColumnName + "] " + type, conn);
addcolumn.ExecuteNonQuery();
}catch (Exception ex2) { }
}
}
bulk.WriteToServer(dt);
Console.WriteLine("Bulk Insert completed table:" + dt.TableName);
}
conn.Close()
}catch (Exception ex)
{
Console.WriteLine(ex.Message.ToString() + "\n" + ex.StackTrace.ToString());
}
finally
{
ds1.Clear();
ds1.Dispose();
}