C# SSIS 如何遍历列并设置为空
C# SSIS How to iterate through columns and set to null
我需要在 SSIS 中将任何空字符串列设置为实际空值
通常我可以只使用派生列并将其设置为 NULL(DSTR, 18, 1252)
由于我有很多字段并且想一次性完成,所以我决定使用脚本组件来完成。这是目前的代码
foreach (PropertyInfo inputColumn in Row.GetType().GetProperties())
{
if (!inputColumn.Name.EndsWith("IsNull")
{
if (inputColumn.GetValue(Row, null).ToString().Equals(""))
{
inputColumn.SetValue(Row, null, null);
}
}
}
但是它抛出这个错误:
[Script Component [11692]] Error: System.NullReferenceException: Object reference not set to an instance of an object.
at
Microsoft.SqlServer.Dts.Pipeline.ScriptComponentHost.HandleUserException(Exception e)
at
Microsoft.SqlServer.Dts.Pipeline.ScriptComponentHost.ProcessInput(Int32 inputID, PipelineBuffer buffer)
at Microsoft.SqlServer.Dts.Pipeline.ManagedComponentHost.HostProcessInput(IDTSManagedComponentWrapper100 wrapper, Int32 inputID, IDTSBuffer100 pDTSBuffer, IntPtr bufferWirePacket)
如何在派生列中将其设置为 NULL(type) 的等价物?
根据我的评论,只需将等效的 _IsNull 属性 设置为 true。
Row.GetType().GetProperty(inputColumn.Name + "_IsNull").SetValue(Row, true, null);
我需要在 SSIS 中将任何空字符串列设置为实际空值
通常我可以只使用派生列并将其设置为 NULL(DSTR, 18, 1252)
由于我有很多字段并且想一次性完成,所以我决定使用脚本组件来完成。这是目前的代码
foreach (PropertyInfo inputColumn in Row.GetType().GetProperties())
{
if (!inputColumn.Name.EndsWith("IsNull")
{
if (inputColumn.GetValue(Row, null).ToString().Equals(""))
{
inputColumn.SetValue(Row, null, null);
}
}
}
但是它抛出这个错误:
[Script Component [11692]] Error: System.NullReferenceException: Object reference not set to an instance of an object. at
Microsoft.SqlServer.Dts.Pipeline.ScriptComponentHost.HandleUserException(Exception e) at
Microsoft.SqlServer.Dts.Pipeline.ScriptComponentHost.ProcessInput(Int32 inputID, PipelineBuffer buffer) at Microsoft.SqlServer.Dts.Pipeline.ManagedComponentHost.HostProcessInput(IDTSManagedComponentWrapper100 wrapper, Int32 inputID, IDTSBuffer100 pDTSBuffer, IntPtr bufferWirePacket)
如何在派生列中将其设置为 NULL(type) 的等价物?
根据我的评论,只需将等效的 _IsNull 属性 设置为 true。
Row.GetType().GetProperty(inputColumn.Name + "_IsNull").SetValue(Row, true, null);