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

  • SEARCH
  • Home
  • 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 7610009
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T01:18:56+00:00 2026-05-31T01:18:56+00:00

Im trying to create a small application where a user submit personal info and

  • 0

Im trying to create a small application where a user submit personal info and the data are saved on an Access DB.

The error that is returning does not make any sense because I am trying to insert the correct amount of values into the table.

The values are first,last,age, and gender.

This is my code followed by the error that i’m getting when i press the submit button.

Thanks for all your help.

<pre>
<%@ Page Language="C#" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>

<script runat="server">
public void btnSubmit_Click(object sender, EventArgs e)
{
    // Create and configure connection string.
    OleDbConnection c = new OleDbConnection();
    c.ConnectionString = 
        "Provider=Microsoft.ACE.OLEDB.12.0;" +
        "Data Source=d:/ectserver/gnicolai/Database/application.accdb;";

    // Open connection.
    c.Open();

    // Get data from textboxes.
    string last = txtLastName.Text;
    string first = txtFirstName.Text;
    string gender = txtGender.Text;
    int  age = int.Parse(txtAge.Text);

    // Compose SQL command string.
    string sql = "INSERT INTO Applicant VALUES"  + 
        "('" + last + "', '" + first + 
        "', '" + gender + "',"  + age + ");";

    // Show SQL insert statement.
    litMessage.Text = 
        "Data submitted with SQL query string<br />" + sql;

    // Create command object and execute insert statement.
    OleDbCommand command = new OleDbCommand(sql, c);
    command.ExecuteNonQuery();

    // Close connection.
    c.Close();
}
</script>

<html>

<head>
<title>grocery-display3.aspx Example</title>
<link rel="stylesheet" class="text/css" 
                       href="../examples.css" />
<style type="text/css">
td  { padding-left:0.15cm;
      padding-right:0.15cm;
      padding-top:0.15cm;
      padding-bottom:0.15cm; }
</style>
</head>

<body>

<h2>PersonInfo3 Example</h2>

<p>Submit age, gender, and age for a person; 
     store this information in a database.
     Retrieve this data with the ViewPersons page. </p>

<form id="frmSelect" runat="server">

<table>
<tr> 
    <td class="r">Last Name</td>
    <td><asp:TextBox ID="txtFirstName" runat="server" 
            CssClass="ctrl" /></td>
</tr>
<tr> 
    <td class="r">First Name</td>
    <td><asp:TextBox ID="txtLastName" runat="server" 
            CssClass="ctrl" /></td>
</tr>
<tr> 
    <td class="r">Gender</td>
    <td><asp:TextBox ID="txtGender" runat="server"
            CssClass="ctrl"  /></td>
</tr>
<tr> 
    <td class="r">Age</td>
    <td><asp:TextBox ID="txtAge" runat="server" 
            CssClass="ctrl" /></td>    
</tr>
<tr> 
    <td> </td>
    <td><asp:Button ID="btnSubmit" runat="server"
            Text="Submit" CssClass="ctrl" Width="128px"
            OnClick="btnSubmit_Click" /></td>
</tr>
</table>

<p><asp:RangeValidator ID="RangeValidator1" Type="Integer" runat="server" 
      ControlToValidate="txtAge" Display="Static" MinimumValue="0" 
      MaximumValue="130" ErrorMessage="Age must be between 0 and 130" /></p>

<p><asp:Literal ID="litMessage" runat="server" /></p>
</form>

</body>
</html>         

</pre>


<strong>Error</strong>

<pre>
Server Error in '/' Application.

Number of query values and destination fields are not the same.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.Data.OleDb.OleDbException: Number of query values and destination fields are not the same.

Source Error: 


Line 32:     // Create command object and execute insert statement.
Line 33:     OleDbCommand command = new OleDbCommand(sql, c);
Line 34:     command.ExecuteNonQuery();
Line 35:         
Line 36:     // Close connection.

Source File: d:\DePaul\Winter 2012\IT 330\Projects\Proj5-Nicolaides\Proj5-Nicolaides\Default.aspx    Line: 34 

Stack Trace: 


[OleDbException (0x80004005): Number of query values and destination fields are not the same.]
   System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(OleDbHResult hr) +992124
   System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult) +255
   System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult) +188
   System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult) +58
   System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method) +161
   System.Data.OleDb.OleDbCommand.ExecuteNonQuery() +113
   ASP.default_aspx.btnSubmit_Click(Object sender, EventArgs e) in d:\DePaul\Winter 2012\IT 330\Projects\Proj5-Nicolaides\Proj5-Nicolaides\Default.aspx:34
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +111
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +110
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565


</pre>
  • 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-31T01:18:57+00:00Added an answer on May 31, 2026 at 1:18 am

    The ID field that I had on the database table was messing with my insert statement. After viewing the table in design view, I removed the “ID” field and my insert statement works as it should.

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

Sidebar

Related Questions

I am trying create a small web application that allows a user to login
Trying to create a small monitor application that displays current internet usage as percentage
I'm trying to create a small application that interacts with the Product API of
I am trying to create a small application where a user can drag an
I'm trying to create a small VB-application that removes the internal link in Word
I'm trying to create a small application that will copy some .jar files into
I'm trying to create a small Javascript framework that I can use in my
Trying to create a QtRuby application, I get the following error: /usr/lib64/ruby/site_ruby/1.8/Qt/qtruby4.rb:2144: [BUG] Segmentation
I am trying to create a small pop-up in my Android application to let
I am trying to create a button on my access form that allows for

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.