首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在SqlDataSource中使用输出参数

在SqlDataSource中使用输出参数
EN

Stack Overflow用户
提问于 2011-11-16 00:42:43
回答 2查看 10.1K关注 0票数 2

我正在检索一个数据库条目的scope_identity,并且我想在不同的SqlDataSource中使用该变量,主要作为一个,但我无法访问该变量。我将变量显示在msgbox中,并且显示正常,我只是不确定如何在SqlDataSource中访问它。这是我的代码;

这是插入第一个信息并接收scope_identity和_inserted事件的数据源;代码:

代码语言:javascript
运行
复制
<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,我是否应该将其声明为,如果是,是什么类型?代码:

代码语言:javascript
运行
复制
      <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>

先谢谢你,尼克

EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8139874

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档