开发者

Reaching a line of code in one assembly

Take a look at this:

For Each info As FieldInfo In AssemblyInstance.GetType().GetFields(flags)
  If info.FieldType.FullName = "System.Data.SqlClient.SqlDataAdapter" Then
    da = CType(info.GetValue(AssemblyInstance), SqlDataAdapter)
  End If
Next

That Assembly is a class.vb component in which there are the following lines of codes:

Me.SqlDeleteCommand1.CommandText = "DELETE FROM [CLASS] WHERE (([MAIN FACILITY USED] = @Original_MAIN_FACILITY_USED) " & _
    "AND ([START DATE] = @Original_START_DATE) AND ([CentreId] = @Original_CentreId) " & _
    "AND ([RowVer] = @Original_RowVer))"
Me.SqlDeleteCommand1.Connection = Me.SqlConnection1
Me.SqlDeleteCommand1.Parameters.AddRange(New System.Data.SqlClient.SqlParameter() {New System.Data.SqlClient.SqlParameter("@Original_MAIN_FACILITY_USED", Syst开发者_JAVA技巧em.Data.SqlDbType.NVarChar, 0, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "MAIN FACILITY USED", System.Data.DataRowVersion.Original, Nothing), New System.Data.SqlClient.SqlParameter("@Original_START_DATE", System.Data.SqlDbType.DateTime, 0, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "START DATE", System.Data.DataRowVersion.Original, Nothing), New System.Data.SqlClient.SqlParameter("@Original_CentreId", System.Data.SqlDbType.Int, 0, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "CentreId", System.Data.DataRowVersion.Original, Nothing), New System.Data.SqlClient.SqlParameter("@Original_RowVer", System.Data.SqlDbType.Timestamp, 0, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "RowVer", System.Data.DataRowVersion.Original, Nothing)})

i have two lines of code to access parts of the above code. the first one is:

da.SelectCommand.CommandText

which I correctly obtain the following line of code:

"DELETE FROM [CLASS] WHERE (([MAIN FACILITY USED] = @Original_MAIN_FACILITY_USED) " & _
    "AND ([START DATE] = @Original_START_DATE) AND ([CentreId] = @Original_CentreId) " & _
    "AND ([RowVer] = @Original_RowVer))"

But The thing is that I need the following part as well:

Me.SqlDeleteCommand1.Parameters.AddRange(New System.Data.SqlClient.SqlParameter() {New System.Data.SqlClient.SqlParameter("@Original_MAIN_FACILITY_USED", System.Data.SqlDbType.NVarChar, 0, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "MAIN FACILITY USED", System.Data.DataRowVersion.Original, Nothing), New System.Data.SqlClient.SqlParameter("@Original_START_DATE", System.Data.SqlDbType.DateTime, 0, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "START DATE", System.Data.DataRowVersion.Original, Nothing), New System.Data.SqlClient.SqlParameter("@Original_CentreId", System.Data.SqlDbType.Int, 0, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "CentreId", System.Data.DataRowVersion.Original, Nothing), New System.Data.SqlClient.SqlParameter("@Original_RowVer", System.Data.SqlDbType.Timestamp, 0, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "RowVer", System.Data.DataRowVersion.Original, Nothing)})

How can I get the above code? I tried da.SelectCommand.Parameters.ToString() but did not work! Any other solution, guys?


In that case: see http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlparametercollection.aspx

That collection can be retrieved using: da.SelectCommand.Parameters

You can perform a for loop over this collection because you can index each individual parameter either using the index or its name (The size can be retrieved using Count).

Better, you can use the linq extensions Cast to cast the collection to a enumerable of SqlParameter.

No code because i dont know VB ^^

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜