title: Using Output Parameter in SqlDataSource
body: <p>I am retrieving the scope_identity of a db entry, and I want to use that variable in a different SqlDataSource, primarily as an  but I am unable to access the variable.
  I have the variable being displayed in a msgbox, and it is displaying properly, I am just unsure how to access it in the SqlDataSource. Here is my code;</p>
  
  <p>This is the datasource that inserts the first information and received the scope_identity, as well as the _inserted event;
  Code:</p>
  
  <pre><code>&lt;asp:SqlDataSource ID="InsertPatientInfo" runat="server" ConnectionString="&lt;%$ ConnectionStrings:DataConnectionString %&gt;"
  providername="&lt;%$ ConnectionStrings:DataConnectionString.ProviderName %&gt;"
      InsertCommandType="StoredProcedure"
      InsertCommand = "InsertPatInfo"
      OnInserted="InsertPatientInfo_Inserted"&gt;
      &lt;InsertParameters&gt;
          &lt;asp:ControlParameter ControlID = "PatInfoName" Name="PatName" PropertyName="text"/&gt;
          &lt;asp:ControlParameter ControlID = "PatInfoAge" Name="PatAge" PropertyName="text" /&gt;
          &lt;asp:ControlParameter ControlID = "PatInfoState" Name="PatState" PropertyName="selectedvalue" /&gt;
          &lt;asp:ControlParameter ControlID = "PatInfoCountry" Name="PatCountry" PropertyName="selectedvalue" /&gt;
          &lt;asp:ControlParameter ControlID = "PatInfoPhone" Name="PatPhone" PropertyName = "text" /&gt;
          &lt;asp:ControlParameter ControlID = "PatInfoCell" Name="PatCell" PropertyName="Text" /&gt;
          &lt;asp:Parameter DbType="Int32" Direction="Output" Name="PatID" /&gt;
      &lt;/InsertParameters&gt; 
  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
  </code></pre>
  
  <p>Here is the call to the next SqlDataSource, with the InsertCommand included, I'm planning on switching to a stored procedure once I get it working; I continue to get the error, that the scalar varaible @PatID is not set, am I supposed to declare it as a  and if so, what type?
  Code:</p>
  
  <pre><code>      &lt;asp:SqlDataSource ID="InsInqInfo" runat="server" ConnectionString="&lt;%$ ConnectionStrings:DataConnectionString %&gt;"
          providerName="&lt;%$ ConnectionStrings:DataConnectionString.ProviderName %&gt;"
          InsertCommand = "Insert into tblInquirer(InqPatID, InqName, InqState, InqCountry, InqPhone, InqRelation, InqVia, InqCareLevel, InqProgram) VALUES 
          (@PatID, @InqName, @InqState, @InqCountry, @InqPhone, @InqRelation, @InqVia, @InqCareLevel, @InqProgram)"
  
  
  &lt;InsertParameters&gt;
  
              &lt;asp:ControlParameter ControlID = "InqName" Name="InqName" PropertyName="text"/&gt;
              &lt;asp:ControlParameter ControlID = "InqStateList" Name="InqState" PropertyName="selectedvalue" /&gt;
              &lt;asp:ControlParameter ControlID = "InqCountry" Name="InqCountry" PropertyName="selectedvalue" /&gt;
              &lt;asp:ControlParameter ControlID = "InqPhone" Name="InqPhone" PropertyName="Text" /&gt;
              &lt;asp:ControlParameter ControlID = "radInqRel" Name="InqRelation" PropertyName="selectedvalue" /&gt;
              &lt;asp:ControlParameter ControlID = "InitInqVia" Name="InqVia" PropertyName = "selectedvalue" /&gt;
              &lt;asp:ControlParameter ControlID = "CareLevel" Name="InqCareLevel" PropertyName="selectedvalue" /&gt;
              &lt;asp:ControlParameter ControlID = "ProgSelect" Name="InqProgram" PropertyName="selectedvalue" /&gt;     
          &lt;/InsertParameters&gt;
  </code></pre>
  
  <p>Thank you in advance,
  Nick</p>