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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:07:40+00:00 2026-05-27T16:07:40+00:00

I am developing a simple online suggestion application where the user can fill a

  • 0

I am developing a simple online suggestion application where the user can fill a form with his suggestion and submit it directly to the system. The system will send this suggestion to the admin via email. I developed it like the form of the Contact Us page. Now, I want, in addition to sending the suggestion by email, to store the suggestion in the database in order to list all the suggestions in one page.
I created the following table in the database:

SuggestionLog Table: ID, Title, Description, Username

(ID is the primary key and Username is a foreign key to the Users table)

My ASP.NET Code is:

<div ID="contactform">
                <ol>
                    <li>
                        <label for="subject">
                        Subject</label>
                        <asp:TextBox ID="txtSubject" runat="server" CssClass="text"></asp:TextBox>
                        <br />
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" 
                            ControlToValidate="txtSubject" 
                            ErrorMessage="Please enter a subject/title for your suggestion"></asp:RequiredFieldValidator>
                    </li>
                    <li>
                        <label for="message">
                        Your Suggestion</label>
                        <asp:TextBox ID="txtSuggestion" runat="server" cols="50" CssClass="textarea" 
                            rows="6" TextMode="MultiLine"></asp:TextBox>
                        <br />
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" 
                            ControlToValidate="txtSuggestion" ErrorMessage="Please enter your suggestion"></asp:RequiredFieldValidator>
                    </li>
                    <li class="buttons">
                        <asp:ImageButton ID="imageField" runat="server" imageurl="images/Send.gif" 
                            OnClick="btnSubmit_Click" />

                    </li>
                </ol>
            </div>

and my code-behind is:

protected void btnSubmit_Click(object sender, ImageClickEventArgs e)
    {
        SmtpClient sc = new SmtpClient("MAIL ADDRESS");
        StringBuilder sb = new StringBuilder();
        MailMessage msg = null;


        sb.Append("Message   : " + txtSuggestion.Text + "\n");

        try
        {
            msg = new MailMessage("",
                "xxxxxxxxxx@gmail.com", "Message from PSSP System",
                sb.ToString());

            sc.Send(msg);
            MultiView1.SetActiveView(ViewConfirm);
        }
        catch (Exception ex)
        {
            throw ex;

        }
        finally
        {

            if (msg != null)
            {
                msg.Dispose();
            }

        }
    }

Now, how can I store the suggestion in the database at the same time that it will be sent to the Admin when the user clicks on the Send button?

  • 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-27T16:07:41+00:00Added an answer on May 27, 2026 at 4:07 pm

    First of all, your code-behind should be dedicated to building your front-end (view). It shouldn’t be troubled with writing/sending emails or database INSERTs. You should really create another tier (controller) to handle that.

    Anyway, to update the database (assuming SQL Server here), you’ll need to pass your title, desc, and username to a function where you’ll create a connection object. You’ll then open it, create a command object with your INSERT SQL, add your parameters, and EXECUTE it. It’ll look something like this:

    using System.Data.SqlClient;
    ....
        SqlConnection objConn = new SqlConnection("Data Source=MYDBSERVER,3306;User ID=kingRoland;Password=12345;Initial Catalog=suggestionDB");
        objConn.Open();
        SqlCommand objCMD = new SqlCommand();
        objCMD.Connection = objConn;
        objCMD.CommandText = "INSERT INTO SuggestionLog (Title,Description,Username) VALUES(@title, @desc, @user)";
        objCMD.Parameters.Clear();
        objCMD.Parameters.AddWithValue("title",strTitle);
        objCMD.Parameters.AddWithValue("desc",strDesc);
        objCMD.Parameters.AddWithValue("user",strUser);
    
        try
        {
            objCMD.ExecuteNonQuery();
        }
        catch (SqlException e)
        {
            writeToLog(e.InnerException.ToString());
        }
        objConn.Close();
    

    ID is omitted because I’m assuming that your ID field would be an autonumber, so the DB would generate a value for you. If not, you’ll need to pass that along as well. Also, this code assumes a custom error log function referenced by “writeToLog”.

    I should also mention that your sql connection info should be retrieved from your web.config, not hard-coded into the function.

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

Sidebar

Related Questions

Can anyone recommend a good Java game engine for developing simple tile-based games? I'm
Hi I am developing a simple application based upon ASP.NET MVC. I have altered
I am developing a simple web page to be viewed after an iphone application
I am developing a PhoneGap application for Android (will work on iOS too). The
i'm developing simple cms application. i want to integrate number of hits for some
I started developing simple application in WPF and XAML. I want to try accessign
im developing a simple Mxml application using flex 3. I have used simple text
Background Developing a simple web application (Eclipse + JBoss + Apache Tomcat) to generate
How can I start developing simple iOS tweaks for Cydia? What's the difference in
I am developing simple application using JSF with richfaces. I want to upload folder(select

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.