ObjectDataSource来.插入总是返回-1
本文关键字:返回 插入 ObjectDataSource | 更新日期: 2023-09-27 18:14:02
试图获得新的行ID,我已经到处看,并尝试了常见的解决方案,似乎为其他人工作。我不能更改数据库,但我知道参数VersionID是用范围Identity设置的。SP中的最后一行是返回(@@VersionID)我还尝试将其放在插入的事件
上protected void VersionDataSource_Inserted(object sender, ObjectDataSourceStatusEventArgs e)
{
int returnValue = (int)e.OutputParameters;
}
但是它总是返回-1,我似乎无法得到新的行ID,我尝试使参数方向输出以及returnValue。我完全不知所措,我花了一整天的时间在这些垃圾上。
Outputparameters似乎是一个字典,我建议
int returnValue = (int)e.OutputParameters["VersionID"].Value;
您还没有发布标记,但是您应该有一个参数定义为输出参数:
<asp:Parameter Direction="Output" Name="VersionID" Type="Int32" />
使用以上代码,您应该能够得到如下输出值:
protected void SqlDataSource1_Inserted(object sender, SqlDataSourceStatusEventArgs e)
{
int id = Convert.ToInt32(e.Command.Parameter["VersionID"].Value);
}