【发布时间】:2011-11-15 16:42:42
【问题描述】:
我正在检索 db 条目的 scope_identity,并且我想在不同的 SqlDataSource 中使用该变量,主要用作但我无法访问该变量。 我将变量显示在 msgbox 中,并且显示正确,我只是不确定如何在 SqlDataSource 中访问它。这是我的代码;
这是插入第一个信息并接收到scope_identity,以及_inserted事件的数据源; 代码:
<asp:SqlDataSource ID="InsertPatientInfo" runat="server" ConnectionString="<%$ ConnectionStrings:DataConnectionString %>"
providername="<%$ ConnectionStrings:DataConnectionString.ProviderName %>"
InsertCommandType="StoredProcedure"
InsertCommand = "InsertPatInfo"
OnInserted="InsertPatientInfo_Inserted">
<InsertParameters>
<asp:ControlParameter ControlID = "PatInfoName" Name="PatName" PropertyName="text"/>
<asp:ControlParameter ControlID = "PatInfoAge" Name="PatAge" PropertyName="text" />
<asp:ControlParameter ControlID = "PatInfoState" Name="PatState" PropertyName="selectedvalue" />
<asp:ControlParameter ControlID = "PatInfoCountry" Name="PatCountry" PropertyName="selectedvalue" />
<asp:ControlParameter ControlID = "PatInfoPhone" Name="PatPhone" PropertyName = "text" />
<asp:ControlParameter ControlID = "PatInfoCell" Name="PatCell" PropertyName="Text" />
<asp:Parameter DbType="Int32" Direction="Output" Name="PatID" />
</InsertParameters>
Protected Sub InsertPatientInfo_Inserted(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceStatusEventArgs) Handles InsertPatientInfo.Inserted
Dim PatID As String = e.Command.Parameters("@PatID").Value
MsgBox(PatID, MsgBoxStyle.Critical)
End Sub
这是对下一个 SqlDataSource 的调用,包括 InsertCommand,我计划在它工作后切换到存储过程;我继续收到错误,标量变量@PatID 未设置,我应该将其声明为 a 吗?如果是,是什么类型? 代码:
<asp:SqlDataSource ID="InsInqInfo" runat="server" ConnectionString="<%$ ConnectionStrings:DataConnectionString %>"
providerName="<%$ ConnectionStrings:DataConnectionString.ProviderName %>"
InsertCommand = "Insert into tblInquirer(InqPatID, InqName, InqState, InqCountry, InqPhone, InqRelation, InqVia, InqCareLevel, InqProgram) VALUES
(@PatID, @InqName, @InqState, @InqCountry, @InqPhone, @InqRelation, @InqVia, @InqCareLevel, @InqProgram)"
<InsertParameters>
<asp:ControlParameter ControlID = "InqName" Name="InqName" PropertyName="text"/>
<asp:ControlParameter ControlID = "InqStateList" Name="InqState" PropertyName="selectedvalue" />
<asp:ControlParameter ControlID = "InqCountry" Name="InqCountry" PropertyName="selectedvalue" />
<asp:ControlParameter ControlID = "InqPhone" Name="InqPhone" PropertyName="Text" />
<asp:ControlParameter ControlID = "radInqRel" Name="InqRelation" PropertyName="selectedvalue" />
<asp:ControlParameter ControlID = "InitInqVia" Name="InqVia" PropertyName = "selectedvalue" />
<asp:ControlParameter ControlID = "CareLevel" Name="InqCareLevel" PropertyName="selectedvalue" />
<asp:ControlParameter ControlID = "ProgSelect" Name="InqProgram" PropertyName="selectedvalue" />
</InsertParameters>
提前谢谢你, 尼克
【问题讨论】: