Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7018125
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:00:12+00:00 2026-05-27T23:00:12+00:00

I have a method that gets the value from text boxes and inserts them

  • 0

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?

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

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?

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

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;
        }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T23:00:13+00:00Added an answer on May 27, 2026 at 11:00 pm

    Technically, the TextBox.Text property will never be null. If no value is present in the form, it will be string.Empty.

    You can test for empty strings with something like this:

    if (!string.IsNullOrEmpty(AnswerBox1.Text))
        int answerId = SendData.InsertAnswer(AnswerBox1.Text, questionId, QuestionnaireId);
    

    Note that I’m not entirely sure what your overall goal here is. Maybe I’m missing something. It sounds like you’re asking how to check each TextBox for empty values and perform an insert on the ones which have non-empty values. So I guess you’d do something similar to the above several times. There are other ways to do it, you can wrap it all in helper methods, etc. But in general you’re just testing for a “non-insertable according to the business rules” value.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a method that gets rows from my database. It looks like this:
I have a AJAX post method that gets xml data from server. But when
I have created a page called profile.php that gets a value from mainpage.php, by
I have a very basic doubt regarding the method that gets executed when app
I have class method that returns a list of employees that I can iterate
I have a method that can return either a single object or a collection
I have a ListActivity which gets its data from a database query. I also
I am trying to change the value of a set of text boxes (that
I have a class that wraps List<> I have GetValue by index method: public
I have a method that where I want to redirect the user back to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.