Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 SQL Server 2005 Forums
 Analysis Server and Reporting Services (2005)
 Dynamic Table to Excel 2005 Sql
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Posting Yak Master

152 Posts

Posted - 08/06/2013 :  12:12:21  Show Profile  Reply with Quote
I have a script task which has 100 predefined output columns
I have a source table whose column count changes

I am trying to set the values to the output columns if the column is there.
If the column is not there it will not be set (null)

I have a script task to do this.

Public Overrides Sub PreExecute()
Dim Conn As System.Data.SqlClient.SqlConnection
Dim Cmd As System.Data.SqlClient.SqlCommand
Conn = New System.Data.SqlClient.SqlConnection("Data Source=servername;Initial Catalog=databasename;Integrated Security=SSPI;")
Cmd = New System.Data.SqlClient.SqlCommand("Select * from dbo.Temp_Totals", Conn)
Reader = Cmd.ExecuteReader()
End Sub

Public Overrides Sub CreateNewOutputRows()
' Add rows by calling AddRow method on member variable called "<Output Name>Buffer"
' E.g., MyOutputBuffer.AddRow() if your output was named "My Output"
Dim output = ComponentMetaData.OutputCollection(0)


Dim MaxField = Reader.FieldCount
Dim columnName As String
While (Reader.Read())
For i As Integer = 0 To MaxField - 1
columnName = "column" + i.ToString()
Dim propInfo As System.Reflection.PropertyInfo
propInfo = OutputValuesBuffer.GetType().GetProperty(columnName)
propInfo.SetValue(OutputValuesBuffer, Reader(i), Nothing)
'OutputValuesBuffer.GetType().GetProperty(columnName).SetValue(OutputValuesBuffer, Reader(i), Nothing) ---> i just want to set the column value from the reader.

End While

End Sub

I am getting object reference not set to an instance of an object in the line
propInfo.SetValue(OutputValuesBuffer, Reader(i), Nothing)
What am I doing wrong ?


Edited by - AAAV on 08/06/2013 12:12:43
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.02 seconds. Powered By: Snitz Forums 2000