How can I include values from text boxes that are not NULL?
<p>I have a method that gets the value from text boxes and inserts them into the database.
How can I parse the values from only text boxes which have had text typed into them?</p>

<p>For example if textbox 4, 5  6 are empty then I do not want them to be parsed to the insert method.</p>

<p>This is what I have written to insert ONE answer into the database. How can I modify it to include only those text boxes that are NOT null?</p>

<pre><code>&lt;div id="answer_wrapper"&gt;
                &lt;div class="answer"&gt;
                    &lt;h3 class="new"&gt;Answer 1&lt;/h3&gt;
                    &lt;asp:TextBox ID="AnswerBox1" runat="server" CssClass="form" Width="300px"&gt;&lt;/asp:TextBox&gt;
                &lt;/div&gt; &lt;!-- end answer --&gt;
                &lt;div class="answer"&gt;
                    &lt;h3 class="new"&gt;Answer 2&lt;/h3&gt;
                    &lt;asp:TextBox ID="AnswerBox2" runat="server" CssClass="form" Width="300px"&gt;&lt;/asp:TextBox&gt;
                &lt;/div&gt; &lt;!-- end answer --&gt;
                &lt;div class="answer"&gt;
                    &lt;h3 class="new"&gt;Answer 3&lt;/h3&gt;
                    &lt;asp:TextBox ID="AnswerBox3" runat="server" CssClass="form" Width="300px"&gt;&lt;/asp:TextBox&gt;
                &lt;/div&gt; &lt;!-- end answer --&gt;
                &lt;div class="answer"&gt;
                    &lt;h3 class="new"&gt;Answer 4&lt;/h3&gt;
                    &lt;asp:TextBox ID="AnswerBox4" runat="server" CssClass="form" Width="300px"&gt;&lt;/asp:TextBox&gt;
                &lt;/div&gt; &lt;!-- end answer --&gt;
                &lt;div class="answer"&gt;
                    &lt;h3 class="new"&gt;Answer 5&lt;/h3&gt;
                    &lt;asp:TextBox ID="AnswerBox5" runat="server" CssClass="form" Width="300px"&gt;&lt;/asp:TextBox&gt;
                &lt;/div&gt; &lt;!-- end answer --&gt;
                &lt;div class="answer"&gt;
                    &lt;h3 class="new"&gt;Answer 6&lt;/h3&gt;
                    &lt;asp:TextBox ID="AnswerBox6" runat="server" CssClass="form" Width="300px"&gt;&lt;/asp:TextBox&gt;
                &lt;/div&gt; &lt;!-- end answer --&gt;
</code></pre>

<p> </p>

<pre><code>protected void FinishQnrButton_Click(object sender, EventArgs e)
        {
            int QuestionnaireId = (int)Session["QuestionnaireID"];  
            SendData = new OsqarSQL();
            int questionId = SendData.InsertQuestions(QuestionName.Text, Int32.Parse(QuestnType.SelectedValue), QuestionnaireId);
            int answerId = SendData.InsertAnswer(AnswerBox1.Text, questionId, QuestionnaireId);
            Response.Redirect("~/buildq/Confirm_Questionnaire.aspx");

        } // End NewQNRButton_Click

        public int InsertAnswer(string AnswerTitle, int QuestionID, int QuestionnaireID)
        {
            int returnValue = 0;
            SqlCommand myCommand = new SqlCommand("NewAnswer", _productConn);
            myCommand.CommandType = CommandType.StoredProcedure;
            myCommand.Parameters.Add(new SqlParameter("@ANSWERTITLE", SqlDbType.NVarChar));
            myCommand.Parameters.Add(new SqlParameter("@QUESTION_ID", SqlDbType.Int));
            myCommand.Parameters.Add(new SqlParameter("@QUEST_ID", SqlDbType.Int));
            myCommand.Parameters.Add("@ANSWER_ID", SqlDbType.Int, 0, "ANSWER_ID");
            myCommand.Parameters["@ANSWER_ID"].Direction = ParameterDirection.Output;
            myCommand.Parameters[0].Value = AnswerTitle;
            myCommand.Parameters[1].Value = QuestionID;
            myCommand.Parameters[2].Value = QuestionnaireID;
            _productConn.Open();
            myCommand.ExecuteNonQuery();
            returnValue = (int)myCommand.Parameters["@ANSWER_ID"].Value;
            _productConn.Close();
            return returnValue;
        }
</code></pre>
