dbTalk Databases Forums  

Transfert Msde to excel with vb.net or c#

microsoft.public.sqlserver.dts microsoft.public.sqlserver.dts


Discuss Transfert Msde to excel with vb.net or c# in the microsoft.public.sqlserver.dts forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
christophe.bertieaux@wanadoo.fr
 
Posts: n/a

Default Transfert Msde to excel with vb.net or c# - 02-12-2004 , 03:25 AM






Hello,

I'm newbie in dts and i try to export date from msde2000 to excel with
vb.net or c#.

So i defined 3 steps in my programm
1. Drop table
2. Create table
3. Add Data

Vhen i execute this program, the data are not deleted in my
spreadsheet
but it continues to append rows to existing rows.

I don't understand where is the problem !!!

Thanks in advance.


This is my programm :

using DT = Microsoft.SQLServer.DTSPkg80;


DT.PackageClass pack = new DT.PackageClass();
pack.Name = "test";
pack.Description = " test de DTS";
pack.FailOnError = true;

// Définition des connections

// Connection 1
DT.Connection cnn = pack.Connections.New("SQLOLEDB.1");
cnn.Name = "Source";
cnn.ID = 1;
cnn.ConnectionTimeout = 60;
pack.Connections.Add(cnn);
cnn = null;
// Connection 2
cnn = pack.Connections.New("Microsoft.Jet.OLEDB.4.0");
cnn.ID = 2;
cnn.ConnectionProperties.Item("Extended Properties").Value = "Excel
8.0;HDR=YES;";
pack.Connections.Add(cnn);
cnn = null;

// ---------------------------------------------------
// Creation des étapes
// ----------------------------------------------------

DT.Step ostep = pack.Steps.New();
ostep.Name = "Etape1";
ostep.TaskName = "Tache1";
pack.Steps.Add(ostep);
ostep = null;

ostep = pack.Steps.New();
ostep.Name = "Etape2";
ostep.TaskName = "Tache2";
pack.Steps.Add(ostep);
ostep = null;

ostep = pack.Steps.New();
ostep.Name = "Etape3";
ostep.TaskName = "Tache3";
pack.Steps.Add(ostep);
ostep=null;

ostep = pack.Steps.Item("Etape2");
DT.PrecedenceConstraint pr =
ostep.PrecedenceConstraints.New("Etape1");
pr.StepName = "Etape1";
pr.PrecedenceBasis =0;
pr.Value = 4;
ostep.PrecedenceConstraints.Add(pr);
pr = null;
ostep = null;
ostep = pack.Steps.Item("Etape3");
pr = ostep.PrecedenceConstraints.New("Etape2");
pr.StepName = "Etape2";
pr.PrecedenceBasis = 0;
pr.Value = 4;
ostep.PrecedenceConstraints.Add(pr);
pr = null;
ostep = null;

//------------------------------------------------------
// Création des taches
//---------------------------------------------------

DT.Task ta = pack.Tasks.New("DTSExecuteSQLTask");
DT.ExecuteSQLTask oc = (Microsoft.SQLServer.DTSPkg80.ExecuteSQLTask
)ta.CustomTask;
oc.Name = "Tache1";
oc.ConnectionID = 2;
oc.SQLStatement = "DROP TABLE `table1`";
pack.Tasks.Add(ta);
oc = null;
ta = null;

ta = pack.Tasks.New("DTSExecuteSQLTask");
oc = (Microsoft.SQLServer.DTSPkg80.ExecuteSQLTask )ta.CustomTask;
oc.Name = "Tache2";
oc.ConnectionID = 2;
oc.SQLStatement = "CREATE TABLE `table1` (`col1` varchar(40)) ";
pack.Tasks.Add(ta);
oc = null;
ta = null;

ta = pack.Tasks.New("DTSDataPumpTask");
DT.DataPumpTask oc1 = (Microsoft.SQLServer.DTSPkg80.DataPumpTask)
ta.CustomTask;
oc1.Name = "Tache3";
oc1.SourceConnectionID = 1;
oc1.SourceSQLStatement = " SELECT sqlcol1 from sqltable ";
oc1.DestinationConnectionID = 2;
oc1.DestinationObjectName = "table1$";
DT.Transformation trans = oc1.Transformations.New
"DTSPump.DataPumpTransformCopy");
trans.Name = "Trans1";
trans.SourceColumns.AddColumn ("sqlcol1",1);
trans.DestinationColumns.AddColumn("col1",1);
oc1.Transformations.Add(trans);
pack.Tasks.Add(ta);
oc = null;
ta = null;
// ----------------------------------------
// execution
// -------------------------------------

{
pack.Execute();
foreach(DT.Step st in pack.Steps)
{
MessageBox.Show(st.Name + " -> " + st.ExecutionResult.ToString() );
}
pack.UnInitialize();

Reply With Quote
  #2  
Old   
Norman
 
Posts: n/a

Default RE: Transfert Msde to excel with vb.net or c# - 02-13-2004 , 01:01 PM






Christophe

I had the same issue using the DTS Designer. It would not clear the Excel spreadsheet. My work around was to save an empty spreadsheet under a different name. I then delete the last filled spreadsheet file and copy the empty one to the filled name

ERASE \\Server\D$\TEMP\Users.xl
COPY \\Server\D$\TEMP\UsersEmpty.xls \\Server\D$\TEMP\Users.xl

There may be a way to do it using the DTS properties and methods, but I was not able to find it

Norman

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.