The below method is used to bulk insert in to a table by using c# from a datatable.
using System.Data;
using System.Data.SqlClient;
public int BulkInsert(DataTable dt, string TableName, string ConnectionString)
{
 int returnValue = -1;
 SqlConnection oConn = new SqlConnection(ConnectionString);
 oConn.Open();
 SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM " + TableName,oConn);
 da.SelectCommand.Connection = oConn;
 DataSet ds = new DataSet();
 SqlCommandBuilder oCmd = new SqlCommandBuilder(da);
 try
 {
  da.Fill(ds);
  returnValue = da.Update(dt);
 }
 catch (Exception ex)
 {
  throw ex;
 }
 finally
 {
  oConn.Close();
  oCmd.Dispose();
 }
 return returnValue;
}
...S.VinothkumaR.
Subscribe to:
Post Comments (Atom)

2 comments:
I am simply out of words after reading your blog. I want to appreciate the way you handled such a complicated subject.
Buy Caverta
buy Edegra
Buy Forzest
Buy generic Levitra
Online Generic Viagra
Nice post...... A big task in a very simple word
Dot Net World
Post a Comment