title: How to Pass Textbox value to SQLDataSource and Fire MessageBox based on Query Result?
body: <p>I've created a simple form that contains a textbox prompting the user to enter an ID.  There's a submit button on the form and a SQLDataSource that wires up the textbox value as a parameter for the query.  </p>
  
  <pre><code>&lt;fieldset&gt;
  &lt;asp:Label runat="server" ID="lblAcctNo"&gt;Please enter the account number:&lt;/asp:Label&gt;
  &lt;asp:TextBox runat="server" ID="txtAcctNo"&gt;&lt;/asp:TextBox&gt;
  &lt;asp:Button runat="server" ID="btnSubmit" Text="Submit" /&gt;
  &lt;/fieldset&gt;
  
  &lt;asp:SqlDataSource ID="sdsMMSPts" runat="server" 
  ConnectionString="&lt;%$ ConnectionStrings:mmsptsConnectionString %&gt;" 
  
  SelectCommand="SELECT [Recommended], [PatientId] FROM [Patients] WHERE ([PatientId] = @PatientId)"&gt;
  &lt;SelectParameters&gt;
      &lt;asp:ControlParameter ControlID="txtAcctNo" Name="PatientId" 
          PropertyName="Text" Type="String" /&gt;
  &lt;/SelectParameters&gt;
  &lt;/asp:SqlDataSource&gt;
  </code></pre>
  
  <p>I've seen examples where a SQl connection is established in codebehind.  Is that necessary, or does the above SQLDataSource take care of that?  Can anyone share some good links to creating message boxes based on query results?  In my case, if Recommended is 1 then messaage 1 would need to be show, if Reccommended is 2 then message 2 would need to be shown.  If the UserID is invalid, the third message needs to be shown.  How do I accomplish this?</p>
  
  <p>UPDATE:<br>
  In my codebehind, I've written the following thus far:</p>
  
  <pre><code>protected void Page_Load(object sender, EventArgs e)
      {
          string connString = System.Configuration.ConfigurationManager.ConnectionStrings
          ["mmsptsConnectionString"].ConnectionString;
  
          SqlConnection sqlconn = new SqlConnection(connString);
          sqlconn.Open();
  
          SqlCommand cmd = new SqlCommand();
          cmd.Connection = connString;
          cmd.CommandType = SqlDataSourceCommandType.StoredProcedure;
          cmd.Parameters.Add(new SqlParameter ("@PatientId", SQLDbType.varchar ));
  
          using (var reader = cmd.ExecuteReader()) 
          {while reader.Read()
                      txtAcctNo.Text=cmd.Parameters("@PatientId")
          }
  
      }
  </code></pre>
  
  <p>My intent here is to call my stored procedure and return the results after binindg @PatientId to the txtAcctNo.Text.  I'm a bit rusty on the SqlClient stuff, what further steps are needed to get the results from my stored procedure?  One of the output parametsrs is @Recommended which is a bit field.  How would I evaluate the parameter value and trigger either a message box alert or a label control based on the value of this paramenter?  For example, if @Recommended = 1 then output "Message 1" to label1.text else output "Message 2" to lable1.text</p>