如果 ASP.NET 网页使用ObjectDataSource,您可以将其配置为使用使用表值参数的存储过程吗?
用户自定义类型:
CREATE TYPE [dbo].[integer_list_tbltype] AS TABLE
(
[n] [int] NOT NULL,
PRIMARY KEY CLUSTERED
)
存储过程:
CREATE PROCEDURE [dbo].[GeneralReport]
@intList integer_list_tbltype READONLY
AS
BEGIN
SELECT * FROM ...
END
ASP.NET
<asp:ObjectDataSource ID="GeneralDataSource" runat="server"
SelectMethod="GetDataByRange"
TypeName="MyProject.GeneralDataSetTableAdapters.GeneralViewTableAdapter"
>
<SelectParameters>
<asp:Parameter Name="intList" />
</SelectParameters>
</asp:ObjectDataSource>
我尝试像这样连接到 ObjectDataSource 的 Selecting 事件:
protected void GeneralDataSource_Selecting( object sender, System.Web.UI.WebControls.ObjectDataSourceSelectingEventArgs e )
{
var zeroList = new List<SqlDataRecord>();
var tvp_definition = new[] {new SqlMetaData( "n", SqlDbType.Int )};
var sqlDataRecord = new SqlDataRecord( tvp_definition );
sqlDataRecord.SetInt32( 0, 0 );
zeroList.Add( sqlDataRecord );
e.InputParameters[ "intList" ] = zeroList;
}
但这只会导致“System.ArgumentException:必须为 UDT 参数设置 UdtTypeName 属性”。被抛出