Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/wix/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 3.0 为每个InputRow&x2B执行存储过程;SSIS脚本组件_C# 3.0_Ssis_Script Component - Fatal编程技术网

C# 3.0 为每个InputRow&x2B执行存储过程;SSIS脚本组件

C# 3.0 为每个InputRow&x2B执行存储过程;SSIS脚本组件,c#-3.0,ssis,script-component,C# 3.0,Ssis,Script Component,在我的脚本组件中,我试图执行存储过程=>返回多行=>其中需要生成输出行 代码如下: /* Microsoft SQL Server Integration Services Script Component * Write scripts using Microsoft Visual C# 2008. * ScriptMain is the entry point class of the script.*/ using System; using System.Data;

在我的脚本组件中,我试图执行存储过程=>返回多行=>其中需要生成输出行

代码如下:

/* Microsoft SQL Server Integration Services Script Component
 *  Write scripts using Microsoft Visual C# 2008.
 *  ScriptMain is the entry point class of the script.*/

  using System;
  using System.Data;
  using System.Data.SqlClient;
  using Microsoft.SqlServer.Dts.Pipeline.Wrapper;
  using Microsoft.SqlServer.Dts.Runtime.Wrapper;

  [Microsoft.SqlServer.Dts.Pipeline.SSISScriptComponentEntryPointAttribute]
  public class ScriptMain : UserComponent
{
SqlConnection cnn = new SqlConnection();
IDTSConnectionManager100 cnManager;
//string cmd;
SqlCommand cmd = new SqlCommand();

public override void AcquireConnections(object Transaction)
{
    cnManager = base.Connections.myConnection;
    cnn = (SqlConnection)cnManager.AcquireConnection(null);
}

public override void PreExecute()
{
    base.PreExecute();
}

public override void PostExecute()
{
    base.PostExecute();
}

public override void InputRows_ProcessInputRow(InputRowsBuffer Row)
{
     while(Row.NextRow())  
     {
        DataTable dt = new DataTable();
        cmd.Connection = cnn;
        cmd.CommandText = "OSPATTRIBUTE_GetOPNforOP";
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.Add("@NK", SqlDbType.VarChar).Value = Row.OPNK.ToString();
        cmd.Parameters.Add("@EDWSTARTDATE", SqlDbType.DateTime).Value = Row.EDWEFFECTIVESTARTDATETIME;
        SqlDataAdapter adapter = new SqlDataAdapter(cmd);
        adapter.Fill(dt);

        foreach (DataRow dtrow in dt.Rows)
        {
            OutputValidBuffer.AddRow();
            OutputValidBuffer.OPNK = Row.OPNK;
            OutputValidBuffer.OSPTYPECODE = Row.OSPTYPECODE;
            OutputValidBuffer.ORGPROVTYPEDESC = Row.ORGPROVTYPEDESC;
            OutputValidBuffer.HEALTHSECTORCODE = Row.HEALTHSECTORCODE;
            OutputValidBuffer.HEALTHSECTORDESCRIPTION = Row.HEALTHSECTORDESCRIPTION;
            OutputValidBuffer.EDWEFFECTIVESTARTDATETIME = Row.EDWEFFECTIVESTARTDATETIME;
            OutputValidBuffer.EDWEFFECTIVEENDDATETIME = Row.EDWEFFECTIVEENDDATETIME;
            OutputValidBuffer.OPQI = Row.OPQI;

            OutputValidBuffer.OPNNK = dtrow[0].ToString();
            OutputValidBuffer.OSPNAMETYPECODE = dtrow[1].ToString();
            OutputValidBuffer.NAMETYPEDESC = dtrow[2].ToString();
            OutputValidBuffer.OSPNAME = dtrow[3].ToString();
            OutputValidBuffer.EDWEFFECTIVESTARTDATETIME1 = Row.EDWEFFECTIVESTARTDATETIME;
            OutputValidBuffer.EDWEFFECTIVEENDDATETIME1 = Row.EDWEFFECTIVEENDDATETIME;
            OutputValidBuffer.OPNQI = dtrow[6].ToString();

        }

     }
}
public override void ReleaseConnections()
{
    cnManager.ReleaseConnection(cnn);
}
}

这总是跳过第一行

而(Row.NextRow())总是带来输入缓冲区的第二行

我做错了什么


谢谢

您能将
while
改为
do while
循环吗

do
{
   // all the gubbings here
} while (Row.NextRow());

明白了,我的SqlCommand需要在InputRows\u ProcessInputRow的本地范围内,而不需要执行NextRow()。谢谢