2 Replies - 1485 Views - Last Post: 19 February 2013 - 11:23 AM Rate Topic: -----

#1 Ataxia  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 19-February 13

Access SQL statement error. "Must contain atleast one table / quer

Posted 19 February 2013 - 10:58 AM

Hello, My First post here :)/>

I'm having trouble with an SQL statement that I am using in VB.net . I'm trying to update a Datagrid and database
(Handles dgvStu.CellValueChanged) with new variables that the user has input, But I am getting an error
"Query input must contain atleast one table or query"

Here is my SQL statement:
"INSERT INTO tblStudent (LegalForename, LegalSurname, DoB, Gender) VALUES ('" & LegalFname & "' , '" & LegalSname & "', '" & DoB & "', '" & Gender & "' ) WHERE (((tblStudent.StudentID)= '" & StuID & "' ));"


Here is the entire Subroutine in VB.NET if it's needed:
Private Sub CheckCellChange() Handles dgvStu.CellValueChanged
        Dim StuID As String = dgvStu.CurrentRow.Cells(0).Value
        Dim LegalFname As String = dgvStu.CurrentRow.Cells(1).Value
        Dim LegalSname As String = dgvStu.CurrentRow.Cells(2).Value
        Dim Gender As String = dgvStu.CurrentRow.Cells(3).Value
        Dim DoB As String = dgvStu.CurrentRow.Cells(4).Value
        Dim mysql = "INSERT INTO tblStudent (LegalForename, LegalSurname, DoB, Gender) VALUES ('" & LegalFname & "' , '" & LegalSname & "', '" & DoB & "', '" & Gender & "' ) WHERE (((tblStudent.StudentID)= '" & StuID & "' ));"
        Try
            If LegalFname <> "" Then
                If LegalSname <> "" Then
                    If Gender <> "" Then
                        If DoB <> "" Then
                        End If
                    End If
                End If
            End If
            UpdateDB(mysql)
        Catch ex As Exception
            MsgBox("Something Went Wrong!")
        End Try
        
    End Sub


From my point of view I can see no syntax errors, but a second opinion will be helpful.
I've tried playing around with the syntax to no avail,but the Access Error is fairly ambiguous so I don't really know what's going on.
Thanks
Ataxia .

Is This A Good Question/Topic? 0
  • +

Replies To: Access SQL statement error. "Must contain atleast one table / quer

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9218
  • View blog
  • Posts: 34,619
  • Joined: 12-June 08

Re: Access SQL statement error. "Must contain atleast one table / quer

Posted 19 February 2013 - 11:04 AM

INSERTs typically do not have a 'where' clause.. you know.. because you are adding a brand new row. UPDATEs have where clauses, but not INSERTS.
Was This Post Helpful? 0
  • +
  • -

#3 Ataxia  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 19-February 13

Re: Access SQL statement error. "Must contain atleast one table / quer

Posted 19 February 2013 - 11:23 AM

OK,I changed the statement to:
"UPDATE tblStudent SET LegalForename = '" & LegalFname & "', LegalSurname =  '" & LegalSname & "' , DoB = '" & DoB & "' , Gender = '" & Gender & "' WHERE StudentID = '" & StuID & "' ;"
and it works great, thanks!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1