Results 1 to 10 of 10
  1. #1
    Join Date
    Mar 2015
    Posts
    5

    Unanswered: Error found in Command

    An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in System.Data.dll

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


    what does it mean?

  2. #2
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    With the limited information provided, I would guess that this is caused by an INSERT statement.
    Code:
    /* This would cause 
    INSERT INTO your_table (column_a, column_b)
      VALUES ('a')
    ;
    
    /* as would this */
    INSERT INTO your_table (column_a, column_b)
      VALUES ('a', 'b', 'c')
    ;
    
    /* This would work */
    INSERT INTO your_table (column_a, column_b)
      VALUES ('a', 'b')
    ;
    Basically you need to ensure that the number of columns declared in your insert statement matches the number of columns in the values portion.


    If you don't believe this to be the case then you're going to have to share the offending code with us!
    George
    Home | Blog

  3. #3
    Join Date
    Mar 2015
    Posts
    5

    Error

    Is it okay that I will only select fields to be added in database?

  4. #4
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    probably....
    not seeing the code its tricky to answer

    it could be that you are including an autonumber column in your list of columns, it could be you have a mismatch (wrong number) of columns and values.
    I'd rather be riding on the Tiger 800 or the Norton

  5. #5
    Join Date
    Mar 2015
    Posts
    5

    Error

    Private Sub Form3_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    koneksyon()
    End Sub

    Private Sub btnNext_Click(sender As Object, e As EventArgs) Handles btnNext.Click

    qry = "Insert into tblGuest (GuestID,GuestName,Gender,Address)values('" & _
    txtGuestId.Text & "','" &
    txtName.Text & "','" &
    txtGender.Text & "','" &
    txtAddress.Text & "','" & ")"

    cmd = New OleDb.OleDbCommand(qry, con)
    dr = cmd.ExecuteReader
    If dr.Read = True Then
    txtGuestId.Text = dr(0) + 1
    Else
    txtGuestId.Text =1
    End If

    MsgBox("Succesfully added in database")
    End Sub
    End Class

    here's my database
    Click image for larger version. 

Name:	PROGRAM.jpg 
Views:	5 
Size:	176.8 KB 
ID:	16228

  6. #6
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    text values should be delimited by a pair of either ' or ", but ' is preferred as its the SQL standard
    (FWIW dates in the form yyyy/mm/dd (ISO) or mm/dd/yyyy (US) delimited by #, eg #2015/3/13#)
    numbers shouldn't be delimited but should be an appropriate type for the column receiving the data

    rather than see the VBA code that is creating the SQL can we see the actual SQL which is throwing the error
    if you aren't up to speed on using the debugger (and you should be)... then use a message box to output the value of the VARIABLE qry

    ANd the database picture is meaningless unless we know the table design (the column datatypes and size where appropriate)
    I'd rather be riding on the Tiger 800 or the Norton

  7. #7
    Join Date
    Mar 2015
    Posts
    5

    Cant add in database

    Why I cant add the data in the database?

    Click image for larger version. 

Name:	database.jpg 
Views:	4 
Size:	175.1 KB 
ID:	16230Click image for larger version. 

Name:	vb.jpg 
Views:	6 
Size:	175.6 KB 
ID:	16231

    Is there something wrong in my code?

    Public Class Form3

    Private Sub Form3_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    koneksyon()
    End Sub

    Private Sub btnNext_Click(sender As Object, e As EventArgs) Handles btnNext.Click

    qry = "Insert into tblGuest(GuestName,Gender,Address)values('txtName. text','txtGender.Text','txtAddress.Text')"
    cmd = New OleDb.OleDbCommand(qry, con)
    dr = cmd.ExecuteReader

    MsgBox("Succesfully added in database")

    Form4.Show()
    End Sub
    End Class

  8. #8
    Join Date
    Mar 2015
    Posts
    5

    Insert in database

    Hi! I have question?
    why I cant insert the data in database(Access)?
    The can be added in VB but in nothing appears in my database. I dont know why?
    Click image for larger version. 

Name:	success.png 
Views:	2 
Size:	189.9 KB 
ID:	16232
    Click image for larger version. 

Name:	data.png 
Views:	1 
Size:	173.6 KB 
ID:	16233

    can someone help me?
    here's the code
    Public Class RegistrationForm


    Private Sub btnNext_Click(sender As Object, e As EventArgs) Handles btnNext.Click

    qry = "INSERT INTO tblGuest(GuestName, Gender, Address)VALUES('" &
    txtName.Text & "','" &
    txtGender.Text & "','" &
    txtAddress.Text & "');"

    cmd = New OleDb.OleDbCommand(qry, con)
    dr = cmd.ExecuteReader()

    MsgBox("Succesfully added in database")

    RoomInfoForm.Show()
    End Sub
    Private Sub RegistrationForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    koneksyon()
    End Sub
    End Class

  9. #9
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    Threads merged
    I'd rather be riding on the Tiger 800 or the Norton

  10. #10
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    is this an Access problem or a VB problem?
    what error message, if any, are you getting?

    on the face of it your code seems to be working....
    I'd rather be riding on the Tiger 800 or the Norton

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •