dbエントリのscope_identityを取得していますが、その変数を別のSqlDataSourceで主に使用しますが、その変数にアクセスできません。 変数がmsgboxに表示されていて、正しく表示されていますが、SqlDataSourceで変数にアクセスする方法がわかりません。ここに私のコードです。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
はInsertCommandはが含まれて私はそれが働いて得れば、私は、ストアドプロシージャへの切り替えを計画しています、次のSqlDataSourceの呼び出しです。私は、スカラーvaraible @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>
は、事前にありがとう、 ニック
私はこのチュートリアルを終了しました。私は自分のコードが彼と似ていると思います。問題は、.insertedイベントの外で@PatIDにアクセスできないことです。私はmsgbox()に入れ、正しいIDを表示しますが、別のSqlDataSourceでとして使用することはできませんので、別のデータベーステーブルのリレーショナルキーとして使用できます。これを行うためにとにかくありますか? –