By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,658 Members | 1,501 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,658 IT Pros & Developers. It's quick & easy.

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

adascat
P: 8
Could anyone find out the problem why this is happening? The number of query values I am trying to insert is exactly the same as in my accdb file actually.

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 40: aQuery = aQuery & " Values ('" & PSW & "', '" & UsrName & "', '" & name & "', '" & Email & "', '" & Landline & "', '" & Website & "')"
Line 41: aCommand = New OleDbCommand(aQuery, aConnection1)
Line 42: aCommand.ExecuteNonQuery()
Line 43: aConnection1.Close()
Line 44: lblResults.Text = "Your account has been created and please wait for approval from administrator"


Source File: C:\Users\Lili Wang\Documents\Visual Studio 2010\Projects\WebApplication1\WebApplication1\Regi stration_Employer.aspx.vb Line: 42

Stack Trace:

[OleDbException (0x80004005): Number of query values and destination fields are not the same.]
System.Data.OleDb.OleDbCommand.ExecuteCommandTextE rrorHandling(OleDbHResult hr) +1070856
System.Data.OleDb.OleDbCommand.ExecuteCommandTextF orSingleResult(tagDBPARAMS dbParams, Object& executeResult) +247
System.Data.OleDb.OleDbCommand.ExecuteCommandText( Object& executeResult) +194
System.Data.OleDb.OleDbCommand.ExecuteCommand(Comm andBehavior behavior, Object& executeResult) +58
System.Data.OleDb.OleDbCommand.ExecuteReaderIntern al(CommandBehavior behavior, String method) +167
System.Data.OleDb.OleDbCommand.ExecuteNonQuery() +113
WebApplication1.Registration_Employer.Button1_Clic k(Object sender, EventArgs e) in C:\Users\Lili Wang\Documents\Visual Studio 2010\Projects\WebApplication1\WebApplication1\Regi stration_Employer.aspx.vb:42
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +118
System.Web.UI.WebControls.Button.RaisePostBackEven t(String eventArgument) +112
System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData) +36
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5563




Expand|Select|Wrap|Line Numbers
  1. Imports System.Data
  2. Imports System.Data.OleDb
  3.  
  4. Partial Class Registration_Employer
  5.     Inherits System.Web.UI.Page
  6.  
  7.     Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  8.  
  9.     End Sub
  10.  
  11.     Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
  12.         Dim aConnection, aConnection1 As OleDbConnection
  13.         Dim aConnectionString, aQuery As String
  14.         Dim aDataReader As OleDbDataReader
  15.         Dim aCommand As OleDbCommand
  16.  
  17.         Dim Email As String = txtEmail.Text
  18.         Dim PSW As String = ""
  19.         Dim UsrName As String = txtUsr.Text
  20.         Dim name As String = txtCompanyName.Text
  21.         Dim Landline As String = txtLandline.Text
  22.         Dim Website As String = txtWeb.Text
  23.  
  24.  
  25.         aConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source =" & _
  26.                      Server.MapPath("/App_Data/CS5012ProjectAY201011.accdb")
  27.         aConnection = New OleDbConnection(aConnectionString)
  28.         aQuery = "Select TranslatorEmail from Translator where TranslatorEmail = '" & Email & "'"
  29.         aCommand = New OleDbCommand(aQuery, aConnection)
  30.         aConnection.Open()
  31.         aDataReader = aCommand.ExecuteReader
  32.  
  33.         If (aDataReader.Read() = True) Then
  34.             lblResults.Text = "Account already exists for this person"
  35.             Button1.Enabled = False
  36.         Else
  37.             aConnection1 = New OleDbConnection(aConnectionString)
  38.             aConnection1.Open()
  39.             aQuery = "Insert Into Employer "
  40.             aQuery = aQuery & " Values ('" & PSW & "', '" & UsrName & "', '" & name & "', '" & Email & "', '" & Landline & "', '" & Website & "')"
  41.             aCommand = New OleDbCommand(aQuery, aConnection1)
  42.             aCommand.ExecuteNonQuery()
  43.             aConnection1.Close()
  44.             lblResults.Text = "Your account has been created and please wait for approval from administrator"
  45.             Button1.Enabled = False
  46.         End If
  47.         aDataReader.Close()
  48.         aConnection.Close()
  49.  
  50.  
  51.     End Sub
  52.  
  53. End Class
May 3 '11 #1

✓ answered by Rabbit

This question can't be answered without knowing the definition of the employer table.

Share this Question
Share on Google+
3 Replies


Rabbit
Expert Mod 10K+
P: 12,324
This question can't be answered without knowing the definition of the employer table.
May 3 '11 #2

adascat
P: 8
I've added the s.shot of employer table. haiz it's small.
There are 6 columns in the table:
EmployerPassword, EmployerNickName, CompanyName, CompanyEmail, CompanyTelephone, CompanyURL, and one Click to Add.
Looking at design view, they are all TEXT datatype.
the DB is in accdb format, access 2007.
Attached Images
File Type: jpg Access 2007.jpg (33.6 KB, 201 views)
May 3 '11 #3

adascat
P: 8
It's so interesting when you ask question about definition of the table it makes me re-look at the table and find out the issue. the click to add column is indeed taken as a column and i added an empty string to this column yes it worked out. Thank you :D
May 3 '11 #4

Post your reply

Sign in to post your reply or Sign up for a free account.