我正在检索一个数据库条目的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,我是否应该将其声明为,如果是,是什么类型?代码:
<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>
先谢谢你,尼克
https://stackoverflow.com/questions/8139874
复制相似问题