Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Dynamic Table to Excel 2005 Sql


Dynamic Table to Excel 2005 Sql

Author
Message
AAAV
AAAV
Forum Newbie
Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)

Group: General Forum Members
Points: 9 Visits: 13
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()
MyBase.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)
Conn.Open()
Reader = Cmd.ExecuteReader()
''Reader.c()
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)

'MsgBox(Microsoft.VisualBasic.Information.TypeName(output))

Dim MaxField = Reader.FieldCount
Dim columnName As String
While (Reader.Read())
OutputValuesBuffer.AddRow()
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.
Next

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 ?

Thanks
CozyRoc
CozyRoc
Ten Centuries
Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)

Group: General Forum Members
Points: 1152 Visits: 2235
I would say propInfo is NULL. That's why you are getting the error.

---
SSIS Tasks Components Scripts Services | http://www.cozyroc.com/


Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search