Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void Main()
- {
- try
- {
- String FilePath = Dts.Variables["$Package::DestinationFileName"].Value.ToString();
- String TableName = Dts.Variables["$Package::SourceTableName"].Value.ToString();
- String ConnStr = Dts.Variables["$Project::ConnStr_DataWarehouse"].Value.ToString();
- //SqlConnection Conn = (SqlConnection)(Dts.Connections["DW"].AcquireConnection(Dts.Transaction) as SqlConnection);
- using (SqlConnection Conn = new SqlConnection(ConnStr))
- {
- String Sql = "SELECT * FROM " + TableName;
- if (File.Exists(FilePath))
- {
- try { File.Delete(FilePath); }
- catch (Exception ex) { MessageBox.Show(ex.Message.ToString()); Dts.TaskResult = (int)ScriptResults.Failure; }
- }
- using (DataTable dt = new DataTable())
- {
- using (SqlCommand cmd = new SqlCommand(Sql, Conn))
- {
- Conn.Open();
- using (SqlDataAdapter da = new SqlDataAdapter(cmd))
- {
- da.Fill(dt);
- FileInfo newFile = new FileInfo(FilePath);
- using (ExcelPackage p = new ExcelPackage(newFile))
- {
- using (ExcelWorksheet ws = p.Workbook.Worksheets.Add("RejectetionReport"))
- {
- ws.Cells["A1"].LoadFromDataTable(dt, true);
- p.Save();
- }
- }
- }
- Conn.Close();
- }
- }
- }
- Dts.TaskResult = (int)ScriptResults.Success;
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message.ToString());
- Dts.TaskResult = (int)ScriptResults.Failure;
- }
- }
Add Comment
Please, Sign In to add comment