已经发现可以在vb.net内部执行sql查询。下面的脚本运行良好
公共子主()
''mail variables
Dim myHtmlMessage As MailMessage
Dim mySmtpClient As SmtpClient
Dim value As NetworkCredential
''sql variables
Dim fireAgain As Boolean = True
Dim rowsAffected As Integer
Dim sqlConn As System.Data.SqlClient.SqlConnection
Dim sqlComm As System.Data.SqlClient.SqlCommand
Dim cm As ConnectionManager = Dts.Connections("cnn") ''Retrive the reference to the managed Connections
'' Request an open connection
sqlConn = cm.AcquireConnection(Dts.Transaction)
Dts.Events.FireInformation(0, "", "Connection is: " + sqlConn.State.ToString(), "", 0, fireAgain)
''Do your work
sqlComm = New System.Data.SqlClient.SqlCommand("select count(*) from table", sqlConn)
rowsAffected = sqlComm.ExecuteScalar()
''sqlComm.ExecuteNonQuery() if you do not want to return anything
''Inform SSIS you're done your work
cm.ReleaseConnection(sqlConn)
Dts.Events.FireInformation(0, "", rowsAffected.ToString() + " rows updated.", "", 0, fireAgain)
'MsgBox(rowsAffected.ToString())
myHtmlMessage = New MailMessage("email", "email", "This is a testing from VB script Task", rowsAffected.ToString)
mySmtpClient = New SmtpClient("send.company.net")
mySmtpClient.Port = 585
value = New NetworkCredential("email", "pwd") ''this is the line added
mySmtpClient.Credentials = value
mySmtpClient.EnableSsl = True
mySmtpClient.Send(myHtmlMessage)
Dts.TaskResult = ScriptResults.Success
End Sub
我的问题是,如果我想执行返回 Vb.net SSIS 脚本任务中的结果集的数据命令怎么办?在第一个脚本中有一个名为 rowsAffected 的变量,它保存计数。但是在第二个脚本中,我需要获得包含超过 12 行的结果集。我可以对打击脚本进行哪些修改?是否需要实现一个字符串数组?
公共子主()
''mail variables
Dim myHtmlMessage As MailMessage
Dim mySmtpClient As SmtpClient
Dim value As NetworkCredential
''sql variables
Dim fireAgain As Boolean = True
Dim rowsAffected As Integer
Dim sqlConn As System.Data.SqlClient.SqlConnection
Dim sqlComm As System.Data.SqlClient.SqlCommand
Dim cm As ConnectionManager = Dts.Connections("cnn") ''Retrive the reference to the managed Connections
'' Request an open connection
sqlConn = cm.AcquireConnection(Dts.Transaction)
Dts.Events.FireInformation(0, "", "Connection is: " + sqlConn.State.ToString(), "", 0, fireAgain)
''Do your work
**sqlComm = New System.Data.SqlClient.SqlCommand("select n.c as [Total_Row_inserted_by this_Load],reverse(substring(reverse(n.[SourceFileName]),1,9)) Filename from()(SELECT count(*) c, [SourceFileName] FROM [Testing-DB].[dbo].[AE_Data] group by [SourceFileName]", sqlConn)**
**rowsAffected = sqlComm.ExecuteScalar()**
''sqlComm.ExecuteNonQuery() if you do not want to return anything
''Inform SSIS you're done your work
cm.ReleaseConnection(sqlConn)
Dts.Events.FireInformation(0, "", rowsAffected.ToString() + " rows updated.", "", 0, fireAgain)
'MsgBox(rowsAffected.ToString())
myHtmlMessage = New MailMessage("email", "email", "This is a testing from VB script Task", rowsAffected.ToString)
mySmtpClient = New SmtpClient("send.company.net")
mySmtpClient.Port = 585
value = New NetworkCredential("email", "pwd") ''this is the line added
mySmtpClient.Credentials = value
mySmtpClient.EnableSsl = True
mySmtpClient.Send(myHtmlMessage)
Dts.TaskResult = ScriptResults.Success
End Sub