不好意思先放下,解决了就撤下去
我在利用DTS导入SQL时,程序不出现错误,但是没有将需要的数据导入到sql中,大家帮我看看:
代码如下:
Button代码:
    string strdespath="bsee";
            
string strsourcepath ="c:\\File\\abc.XLS";
            
string tablename="OTHER_MainPTJob";            
            
string strsql="select  id  from [bsee].[dbo].[OTHER_MainPTJob]";
            AppExportData tryclass
=new AppExportData(strsourcepath,strdespath,tablename,strsql);
            tryclass.ExportData();        
导入类:
    public class AppExportData
        
{
            
//DTS包对象
            public DTS.Package2Class ObjDTS;
            
//源文件路径
            private string strSourceFilePath; 
            
//目标文件路径 
            private string strDestinationFilePath;
            
//导出数据的SQL语句
            private string strSQL;
            
//目标表名
            private string strTableName;
            
//得到目标列名
            private ArrayList arrDestinationColumns;
            
//得到源数据列名
            private ArrayList arrSourceColumns;

            
私有属性

            
公共属性

            
/// <summary>
            
/// 构造函数
            
/// </summary>

            public AppExportData(string strsourcepath,string strdespath,string tablename,string strsql)
            

                strTableName 
= "结果";
                arrDestinationColumns 
= new ArrayList();
                arrSourceColumns 
= new ArrayList();
                strSourceFilePath
=strsourcepath;
                strDestinationFilePath
=strdespath;
                strTableName
=tablename;
                strSQL
=strsql;                
            }


            
导出的全过程

            
/// <summary>
            
/// 在SQL语句中得到目标表的列名 , 本来是想根据SQL语句来决定列名,没有找到高效的分解SQL语句的方法。
            
/// </summary>

            private bool GetColumns()
            
{
                
try
                
{    
                    SqlConnection conn
=new SqlConnection("server=.;uid=sa;pwd=;database=bsee");
                    SqlDataAdapter da
=new SqlDataAdapter(strSQL,conn);
                    DataSet ds 
= new DataSet();    
                    da.Fill(ds,
"qqq");                                    
                    
for ( int i = 0; i < ds.Tables[0].Columns.Count; i++ )
                    
{
                        
this.arrDestinationColumns.Add(ds.Tables[0].Columns[i].ColumnName );
                        
this.arrSourceColumns.Add(ds.Tables[0].Columns[i].ColumnName);
                    }

                    
return true;
                }

                
catch 
                
{
                    
return false;
                }

            }
 
        }

数据库名“bsee”,表名:OTHER_MainPTJob,表内只有一个字段:id
posted on 2007-04-17 20:39  过江  阅读(781)  评论(2编辑  收藏  举报