从dataadapter生成的代码中读取代码行

时间:2011-03-10 15:26:19

标签: .net vb.net

在我的一个项目中,我有以下几行:

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", 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)})

问题是,在另一个项目中,我想阅读这一行:

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)})

在参考其组件后,我写下以下几行:

da.UpdateCommand.Parameters.ToString()

da是添加的dataadapter,因此它可以访问该程序集并从中读取数据。但是下面的代码行正如我所愿,但上面的代码不会。

da.UpdateCommand.CommandText

还有其他解决方案吗?读取包含参数范围的行?

由于

1 个答案:

答案 0 :(得分:1)

DataAdapter中的Parameters对象是SqlParameterCollection对象。如果您正在查找所有值/类型,则可以遍历该集合中的项目并获取所需的值。请参阅documentation以查找所需的值