.NET REFLECTION 中 FieldInfo 类的使用问题
<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")
为什么下面的行我无法访问有关 sqlinsertcommand 的参数集合,但我可以通过以下代码访问 sqlinsertcommand 及其命令文本本身:
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 Ireach that sqlparameter collection via fieldinfo or other related classes in >NET Reflection ? 看起来很粗鲁,但任何帮助甚至建议对我来说都很重要。
<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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
所以“cmd”是“System.Data.SqlClient.SqlCommand”的实例?! - 是的,应该的。
然后它有一个属性“Parameters”来保存您的参数。
so "cmd" is an Instance of "System.Data.SqlClient.SqlCommand" ?! - yes it should.
then it has a property "Parameters" which holds your parameters.