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 6697475
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:27:51+00:00 2026-05-26T06:27:51+00:00

I’m new to ASP. I am trying to insert data from an asp:textbox into

  • 0

I’m new to ASP.

I am trying to insert data from an asp:textbox into a SQL Server database.
I have created a class in the APP_CODE folder which handles the database connection and insert methods.

When button1 is clicked I want it to take the data from the asp:textbox and use the questionnaireSQL.cs file in APP_CODE to update the database.

How can I go about this?

questionnaireSQL.cs

using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using System.Data;

namespace Devworks
{

    public class OscarSQL
    {
        private string _productConnectionString;
        private SqlConnection _productConn;

        public OscarSQL()
        {
            _productConn = new SqlConnection();
            _productConnectionString += "data source=mssql.dev-works.co.uk; Initial Catalog=devworks_oscar;User ID=myusername;Password=mypassword";
            _productConn.ConnectionString = _productConnectionString;
        }

    // Insert New Questionnaire:

        public int InsertQuestionnaire(string QuestName, int CustomerID, int NumberOfQuest)
        {
            int retVal = 0;
            SqlCommand myCommand = new SqlCommand("NewQuestionnaire", _productConn);
            myCommand.CommandType = CommandType.StoredProcedure;
            myCommand.Parameters.Add(new SqlParameter("@QUESTNAME", SqlDbType.NVarChar));
            myCommand.Parameters.Add(new SqlParameter("@CUSTID", SqlDbType.Int));
            myCommand.Parameters.Add(new SqlParameter("@NUMQUEST", SqlDbType.Int));
            myCommand.Parameters.Add("@QUEST_ID", SqlDbType.Int, 0, "QUEST_ID");
            myCommand.Parameters["@QUEST_ID"].Direction = ParameterDirection.Output;
            myCommand.Parameters[0].Value = QuestName;
            myCommand.Parameters[1].Value = CustomerID;
            myCommand.Parameters[2].Value = NumberOfQuest;
            _productConn.Open();
            myCommand.ExecuteNonQuery();
            retVal = (int)myCommand.Parameters["@QUEST_ID"].Value;
            _productConn.Close();
            return retVal;
        }


        // SQL DATAREADER, DATATABLE & NON QUERY UPDATE:

        private void insert(SqlCommand myCommand)
        {
            _productConn.Open();
            myCommand.ExecuteNonQuery();
            _productConn.Close();
        }

        private SqlDataReader getData(SqlCommand myCommand)
        {
            _productConn.Open();
            SqlDataReader myDataReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
            return myDataReader;
        }

        private DataTable createDataTable(SqlDataReader data)
        {
            DataTable retVal = new DataTable();
            retVal.Load(data);
            return retVal;
        }
    }
}

newquestionnaire.aspx

<%@ Page Title="" Language="C#" MasterPageFile="~/Main.Master" AutoEventWireup="true" CodeBehind="new_questionnaire.aspx.cs" Inherits="new_questionnaire" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <div class="container">
        <div class="main">
            <h2 class="new">Add Your Questionnaire</h2>
            <h3>Give your questionnaire a name.</h3>
            <asp:TextBox ID="QuestName" runat="server"></asp:TextBox>
            <h3>CustomerID</h3>
            <asp:TextBox ID="CustomerID" runat="server"></asp:TextBox>
            <h3>Number Of Questions</h3>
            <asp:TextBox ID="NumberOfQuest" runat="server"></asp:TextBox>
            <br />
            <asp:Button  ID="Button1" runat="server" OnClick="Button1_Click" Text="Create" />
        </div> <!-- end main -->
    </div> <!-- end container -->
</asp:Content>

newquestionnaire.aspx.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Devworks;

    public partial class new_questionnaire : System.Web.UI.Page
    {


            protected void Page_Load(object sender, EventArgs e)
            {

            }

            protected void Button1_Click(object sender, EventArgs e)
            {

            }
        }

Thanks in advance

  • 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-26T06:27:52+00:00Added an answer on May 26, 2026 at 6:27 am

    You’ve posted all this code but exactly what can’t you do?
    One has to wonder if you wrote the DAL (Data access layer – your db code) and the Web UI, how is it that you cannot write the click event of a button ironically called Button1 ??

    You take the value of your textbox and on the click of a button insert it into a database.
    When you have a large task seperate it into smaller ones and do each piece until you’ve finished the puzzle.

    According to your code

    OscarSQL c = new OscarSQL(); //btw: not sure why you are not using a static class for this
    int result = c.InsertQuestionnaire(textBox.Text ...);  //add all parameters here
    
    If (result > 0) 
      //good id
    else
      //display error message
    

    Place all of this code behind the button1_click event of your code.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I am currently running into a problem where an element is coming back from
I have a text area in my form which accepts all possible characters from
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have a reasonable size flat file database of text documents mostly saved in
I have a bunch of posts stored in text files formatted in yaml/textile (from
I am trying to loop through a bunch of documents I have to put

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.