ObjectDataSource 可以使用表值参数吗
如果 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 属性”。被扔
If an ASP.NET web page uses an ObjectDataSource, can you configure it to use a stored procedure that uses table-value parameters?
User-defined type:
CREATE TYPE [dbo].[integer_list_tbltype] AS TABLE
(
[n] [int] NOT NULL,
PRIMARY KEY CLUSTERED
)
Stored procedure:
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>
I've tried hooking into the ObjectDataSource's Selecting event like this:
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;
}
But that just results in a "System.ArgumentException: UdtTypeName property must be set for UDT parameters." being thrown
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不知道你为什么要这样做。请参阅此 Lenni Lobel 的博客文章,看看这是否适合您。
*更新:*对于报告,我使用此技术,如 Codebetter.com 上所示
I do not know why you wish to do it this way. See this blog post by Lenni Lobel and see if that works for you.
*UPDATE:*For reporting I use this technique as shown on Codebetter.com
为了完整起见,这是一个可能的解决方案(尽管它可能确实属于“可怕”类别!)
覆盖由强类型数据集生成的表适配器。例如。
然后更新 ObjectDataSource 控件上的 Type 属性以引用这个新类。例如。 “MyProject.GeneralDataSetTableAdapters.GeneralViewTableAdapter2”
希望看到比这更“干净”的答案!
For the sake of completeness, this is a possible solution (though it probably does fall into the 'horrible' category!)
Override the table adapter that was generated by the strongly-typed dataset. eg.
Then update the Type attribute on the ObjectDataSource control to refer to this new class. eg. "MyProject.GeneralDataSetTableAdapters.GeneralViewTableAdapter2"
Would love to see a 'cleaner' answer than this!