尝试在 vb.net 中执行 sql 语句(脚本任务 ssis)。为此创建了连接,请求打开连接并执行并关闭(如下面的代码所示)。变量的值(保存 sql 结果set) 必须返回正确的计数,而不是一直返回 -1 ...知道你这样做了吗?似乎是查询没有执行?
如何在 ssis 脚本任务中使用下面的 vb 代码(请查看)获得正确的计数值?
公共子主()
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(*) AS CNT FROM [Table_1]", sqlConn)
rowsAffected = sqlComm.ExecuteNonQuery()
MsgBox(rowsAffected.ToString()) '''' the value of variable is -1 ???
''Inform SSIS you're done your work
cm.ReleaseConnection(sqlConn)
Dts.Events.FireInformation(0, "", rowsAffected.ToString() + " rows updated.", "", 0, fireAgain)
End Sub
谢谢