To loading the excel file into the database we are using
the Source as Excel Source.
But the problem occurs when the Columns have more than 255
characters. It is failing with truncation.
Problem with the above solution that some time we don’t have
access or authorities to modify the Server Registry value.
To overcome this issue we will use the Script task or
script component.
If we need to do some transformation on the excel data then
we need to use the Script component.
Let’s see the demo
My excel file.
And database table
I am taking a Data flow task.
Taking a script component as a source.
Now I am creating output columns.
Go to script
I am writing below C# code to read the excel file.
public override void CreateNewOutputRows()
{
string FileName = "product.xls";
string strConn;
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=J:\\SSIS1\\excel file\\product.xls;Extended Properties=\"Excel
8.0;HDR=yes;IMEX=0\"";
DataSet output = new DataSet();
using (OleDbConnection conn = new OleDbConnection(strConn))
{
conn.Open();
DataTable
schemaTable = conn.GetOleDbSchemaTable(
OleDbSchemaGuid.Tables, new object[] { null, null, null, "TABLE" });
foreach (DataRow schemaRow in schemaTable.Rows)
{
string sheet = schemaRow["TABLE_NAME"].ToString();
if (!sheet.EndsWith("_"))
{
try
{
DataTable outputTable = new DataTable();
string Query = "SELECT * FROM [" + sheet + "]";
OleDbCommand Ecom = new OleDbCommand(Query,
conn);
DataSet ds = new DataSet();
OleDbDataAdapter oda = new OleDbDataAdapter(Query,
conn);
oda.Fill(ds);
DataTable Exceldt = ds.Tables[0];
foreach (DataRow dr in Exceldt.Rows)
{
Output0Buffer.AddRow();
Output0Buffer.ProductName = dr["productName"].ToString();
Output0Buffer.Cost = dr["cost"].ToString();
Output0Buffer.Description = dr["Description"].ToString();
}
conn.Close();
}
catch (Exception ex)
{
throw new Exception(ex.Message + string.Format("Sheet:{0}.File:F{1}", sheet, FileName), ex);
}
}
}
}
}
|
Save and close it.
Now I am taking the OLEDB destination to load this data into
the database.
Now the package is ready to run.
Before running this package records in the table.
Now running this package.
See the records in the database.
Very informative Blog with good Pictures, i really like it.We provides
ReplyDeleteTempo traveller in Gurgaon
Tempo
traveller in Delhi
Tempo traveller in Faridabad
Tempo traveller in noida
Tempo traveller in Ghaziabad
Tempo traveller in ballabgarh
Tempo traveller gurgaon
Tempo traveller hire Gurgaon
Tempo traveller for outstation
tempo traveller rent Gurgaon
tempo traveller hire noida
Innova taxi in Gurgaon
Innova taxi in Faridabad
Innova taxi in noida
Innova taxi in Ghaziabad
Innova taxi in ballabgarh
Innova taxi gurgaon
Innova taxi hire Gurgaon
Innova taxi for outstation
Innova taxi rent Gurgaon
Innova taxi hire noida
for easy travel call us +91-9999029051 ------------------------------------------------------
Find us on Youtube: Tempo traveller on rent
Location: F28, 1A, DLF Phase 3, Sector 42, Gurugram, Haryana 122002