473,811 Members | 2,749 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Why are number of query values and destination fields not the same?

12 New Member
here is my code. dont seem to know whats the problem. i have 12 data fields in access excluding the ID field.

Expand|Select|Wrap|Line Numbers
  1. Dim strCon As String = "Provider=Microsoft.jet.oledb.4.0;data source=C:\Users\dexter\Documents\desktop\csci14\database\Museum-final.mdb"
  2.         Dim dSet As New DataSet
  3.         Dim M_I As String
  4.         Dim Fname As String
  5.         Dim Lname As String
  6.         Dim Age As Integer
  7.         Dim Address As String
  8.         Dim Email As String
  9.         Dim Tel_Cell As String
  10.         Dim status As String
  11.         Dim Bill As Integer
  12.         Dim Nat As String
  13.         Dim Vis_no As Integer
  14.         Dim DoV As String
  15.  
  16.         M_I = M_ITextBox.Text
  17.         Fname = FirstNameTextBox.Text
  18.         Lname = LastNameTextBox.Text
  19.         Age = Val(AgeTextBox.Text)
  20.         Address = AddressTextBox.Text
  21.         Email = EmailTextBox.Text
  22.         Tel_Cell = Tel_CellTextBox.Text
  23.         status = StatusTextBox.Text
  24.         Bill = Val(BillTextBox.Text)
  25.         Nat = NationalityTextBox.Text
  26.         Vis_no = Val(Visitor_NoTextBox.Text)
  27.         DoV = DateTimePicker1.Text
  28.  
  29.         Try
  30.             cn = New OleDbConnection("Provider=Microsoft.jet.oledb.4.0;data source=C:\Users\dexter\Documents\Visual Studio 2010\Projects\Admission_form\Admission_form\Museum-final.mdb")
  31.  
  32.             cmd = New OleDbCommand("select * FROM Visitor", cn)
  33.             cmd.CommandText = ("INSERT into Visitor ([Visitor_No],[FirstName],[M_I],[LastName],[Address],[Age],[email],[Tel/Cell],[Status],[Bill],[Nationality],[DateOfVisit]) values(" & Vis_no & "," & Fname & "," & M_I & "," & Lname & "," & Address & "," & Age & "," & Email & "," & Tel_Cell & "," & status & "," & Bill & "," & Nat & "," & DoV & ")")
  34.             cn.Open()
  35.             cmd.ExecuteNonQuery()
  36.             clearTxtBox()
  37.  
  38.             cn.Close()
  39.             cn.Dispose()
  40.         Catch ex As System.Exception
  41.             MsgBox(ex.Message, MsgBoxStyle.Critical, "General Error")
  42.         End Try
  43.  
Feb 6 '11 #1
3 5621
Stewart Ross
2,545 Recognized Expert Moderator Specialist
At line 33 in the VALUES part of your statement you will need to enclose each and every text value in single quotes, like this:

Expand|Select|Wrap|Line Numbers
  1. values(" & Vis_no & ", '" & Fname & "','" & M_I & "','" & Lname & "','" & Address & "'," & Age & ",'" & Email & "','" & Tel_Cell & "','" & status & "'," & Bill & ",'" & Nat & "'," & DoV & ")")
Values inserted as string literals MUST be delimited by single quotes on either side of the literal value. I've shown examples of how to do this above, but I might not have caught them all so you'll have to make sure that you do so. Numeric values do not need delimiting, but please be aware that telephone numbers are stored as text strings so they require delimiting, as shown above.

-Stewart
Feb 6 '11 #2
dexter delleva
12 New Member
hello. tnx for your reply. i tried it but still got an error:
Expand|Select|Wrap|Line Numbers
  1.     Syntax error (missing operator)in query expression 
  2.      ",0,'dex','bvn,",",0,",",",0,",'Monday'.
ive entered "dex" in FirstnameTexbox and bvn in M_Itextbox.the monday appears bcos ive set the value of DateOvtextbox to the value of the datetimepicker1 and set it to text as to my code above"
Feb 7 '11 #3
Stewart Ross
2,545 Recognized Expert Moderator Specialist
I added code tags to the error message you quoted above to make the characters shown clearer. If you look at the 'bvn value you will see that it is missing its closing single quote.

As I said in my first reply, values must be enclosed by single quotes, and this one clearly is not.

There also appear to be various double quotes orphaned later in your string, and the example use of single-quotes which I provided would not have resulted in the orphaned double quotes you show in the error statement.

Please bear in mind that in building the SQL statement the parts within double quotes belong to the SQL string itself. The single quotes delimit string literal values supplied from your controls or variables. These delimiters are within the double-quoted string sections, and typically start after the comma for the previous field, and end before the comma for the one after that, like this

Expand|Select|Wrap|Line Numbers
  1. "VALUES(" & var1 & ", '" & var2 & "', '" & var3 & "')"
You must make sure that you have a SQL string which is entirely correct in format. You may have to break it down further so that you can be certain that each part of the substring is correctly formed.
-Stewart
Feb 7 '11 #4

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

Similar topics

3
4464
by: Gert Jan Wiersema | last post by:
Hello all, I'm trying to give users a form in which they can check all 52 weeks of the year. This is done in a $weeks_array thingy. Unfortunately it seems that only 46 of the 52 values (and some other hidden values such as username etc) make it to the next page ($n 0-45). Is there a limit of values in forms? thanx, gert
1
2655
by: Mike | last post by:
My users have to select an value from a fixed selection of values. The obvious choice of control for such a requirement is to use a <select> (i.e. a combo box). My problem is that sometimes, these combo boxes will have a *large* number of values. There could be any number of values in them from 5 to 5 million (unlikely it would be this large but possible). Obviously 5 million is far too much to populate a <select> control with. Does...
3
3465
by: Zb Bornemann | last post by:
Hi All, Ok. Here's what my table looks like: Field1 Field2 Field3 Field4... Record1 1 3 2 9 Record2 9 1 9 4 Record3 1 3 1 2 etc, etc. What I want to do is for each record, count the number of values across the
2
8149
by: ralamo | last post by:
When i execute the following insert query, the above mentioned error is coming. Anything wrong in the query? INSERT INTO ECN_1 (Old_SbPartNo, Old_PartDesc, Old_ManPartNo, Old_Manuf, Old_Vendor, Old_RefDesi, Old_Qty, New_SbPartNo, New_PartDesc, New_ManPartNo,New_Manuf, New_Vendor, New_RefDesi, New_Qty) select * from (select SB0014.SbPartNo, SB0014.partDesc, SB0014.mANpARTnO, SB0014.manufacturer,
3
1735
by: kathyburke40 | last post by:
Odd problem. I have a table in the following format: DocID Question1 Question2 Question3 ------------------------------------------------ 298 1, 2, 3 or 0 Each Question field will have 1,2,3 or 0 if not completed. The number of Question fields will vary. I need to count all the questions, then figure out how many have 0
2
2826
by: yxktmp | last post by:
Hi; I have a main starting query for most of my reporting. I branch out from this query to other queries. This main query contains multiple form control filters (query criterias) . I want to use this query from multiple forms because each report needs different filters on this query. Is there a way to to this like having multiple copies of this query keeping the name same, like an alias name? I would appreciate ideas on this. Thanks! ...
9
3374
by: Kosmos | last post by:
I'm getting this error message: Number of query values and destination fields are not the same. This is the code: INSERT INTO tblDateDifference ( DateDifference ) SELECT tblContracts.EndDate As EndDate, IIf( > EndDate, DaysToCompletion(EndDate), DaysCompleted(EndDate)) AS DateDifference, FROM tblContracts; Can someone please tell me why I'm getting this error message? PLEASE?!?! lol
0
1428
by: R Bandeira | last post by:
How to keep values in fields after ChangeMode to Insert from Edit? I am implementing a re-insert type feature, after an edit. // Change form to insert mode FormView1.ChangeMode(FormViewMode.Insert); // Repopulate the form Label.Text = "12345"; TextBox.Text = "22";
2
5915
by: cypriot | last post by:
Hi. I am developing an application program in java. I use MsAccess for keeping data. I had a problem with sql insert method. public void AddPatient() { String no= numberinput.getText();
3
2867
by: monion | last post by:
One more question. How can I get query values assign them to a variable, but not show them? for example size, $f4 in the following: How can I pass that value $f4 to the form handle page to submit to the database. I can clearly see how to pass $f2 with quantity stuck on the end. Basically, I need to pass 3 things: 1) item#, 2) item#quantity and 3) size to a new database. mysql_select_db("inventory"); $query="SELECT * FROM...
0
10647
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10386
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10398
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10133
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9204
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6889
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5692
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4339
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3865
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.