0
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

Dim resources As   
System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(_Class))
    Me.SqlSelectCommand1 = New System.Data.SqlClient.SqlCommand
    Me.SqlInsertCommand1 = New System.Data.SqlClient.SqlCommand
    Me.SqlUpdateCommand1 = New System.Data.SqlClient.SqlCommand
    Me.SqlDeleteCommand1 = New System.Data.SqlClient.SqlCommand
    Me.SqlDataAdapter1 = New System.Data.SqlClient.SqlDataAdapter
    Me.SqlConnection1 = New System.Data.SqlClient.SqlConnection

.....
.....



Me.SqlInsertCommand1.CommandText = resources.GetString("SqlInsertCommand1.CommandText")
    Me.SqlInsertCommand1.Connection = Me.SqlConnection1
    Me.SqlInsertCommand1.Parameters.AddRange(New System.Data.SqlClient.SqlParameter() {New System.Data.SqlClient.SqlParameter("@MAIN_FACILITY_USED", System.Data.SqlDbType.NVarChar, 0, "MAIN FACILITY USED")

How come with the following line I cannot reach this collection of the parameter regarding to sqlinsertcommand but I can reach the sqlinsertcommand and its commandtext itself by the following code:

Dim flags As BindingFlags = BindingFlags.NonPublic Or BindingFlags.Instance Or BindingFlags.NonPublic
 For Each info As FieldInfo In AssemblyInstance.GetType().GetFields(flags)
  If info.FieldType.FullName = "System.Data.SqlClient.SqlCommand" Then
    cmd = CType(info.GetValue(AssemblyInstance), SqlCommand)
   End If
Next

How can I reach that sqlparameter collection via fieldinfo or other related classes in >NET Reflection? Seems rude but any help or even suggestion means a lot to me.

4

1 回答 1

0

所以“cmd”是“System.Data.SqlClient.SqlCommand”的一个实例?!- 是的,它应该。然后它有一个属性“参数”,它保存你的参数。

于 2011-03-11T09:58:13.830 回答