4 Replies - 2372 Views - Last Post: 18 March 2013 - 03:35 AM Rate Topic: -----

#1 VB ASRAAF007  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 87
  • Joined: 11-April 12

Syntax error(missing Operator) in query expression '@StudentId'

Posted 18 March 2013 - 03:14 AM

hello ,

i have a problem in my codes regarding a syntax error some missing operator in the query expressions here are my codes


 Private Sub OkBtn1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OkBtn1.Click

        If State = ModConnection.Add_Or_Edit_state.AddRecordstate Then

            Call OpenConnection()
            With OleDa

                .InsertCommand = New OleDb.OleDbCommand()
                .InsertCommand.CommandText = "INSERT INTO [student] ([Student Id] , [Full name] , [Email Address] , [Title] , [Phone Number] , [Course Categories] , [Time] , [Year])" & _
                "VALUES  (@Student Id , @Full name , @Email Address , @Title , @Phone Number , @Course Categories , @Time , @Year)"
                .InsertCommand.Connection = OleCn
                .InsertCommand.Parameters.Add("@Student Id", OleDb.OleDbType.VarWChar, 50, "Student Id").Value = Me.stud_id.Text
                .InsertCommand.Parameters.Add("@Full name", OleDb.OleDbType.VarWChar, 50, "Full name").Value = Me.stud_name.Text
                .InsertCommand.Parameters.Add("@Email Address", OleDb.OleDbType.VarWChar, 50, "Email Address").Value = Me.stud_email.Text
                .InsertCommand.Parameters.Add("@Title", OleDb.OleDbType.VarWChar, 50, "Title").Value = Me.stud_title.Text
                .InsertCommand.Parameters.Add("@Phone Number", OleDb.OleDbType.VarWChar, 50, "Phone Number").Value = Me.stud_num.Text
                .InsertCommand.Parameters.Add("@Course Categories", OleDb.OleDbType.VarWChar, 50, "Course Categories").Value = Me.stud_course.Text
                .InsertCommand.Parameters.Add("@Time", OleDb.OleDbType.VarWChar, 50, "Time").Value = Me.stud_time.Text
                .InsertCommand.Parameters.Add("@Year", OleDb.OleDbType.VarWChar, 50, "Year").Value = Me.stud_year.Text
                .InsertCommand.ExecuteNonQuery()

            End With
            Call CloseConnection()
            MsgBox("Record(s) saved...", MsgBoxStyle.Information, "Record(s) saved...")
            If MsgBox("Do you want to add new record(s) ?", MsgBoxStyle.Question + MsgBoxStyle.YesNo, "Confirmarion...") = MsgBoxResult.Yes Then
                Call Cleartext()
                Call TitleItems()
                Call TimeItems()
                Call YearItems()
                Call CourseItems()
                Me.stud_id.Focus()
                Exit Sub
            End If
            Me.Close()
        End If
    End Sub




thanks for replying :)

Is This A Good Question/Topic? 0
  • +

Replies To: Syntax error(missing Operator) in query expression '@StudentId'

#2 andrewsw  Icon User is offline

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3253
  • View blog
  • Posts: 10,908
  • Joined: 12-December 12

Re: Syntax error(missing Operator) in query expression '@StudentId'

Posted 18 March 2013 - 03:18 AM

and where are your error messages, and what lines do they refer to in your posted code?
Was This Post Helpful? 0
  • +
  • -

#3 VB ASRAAF007  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 87
  • Joined: 11-April 12

Re: Syntax error(missing Operator) in query expression '@StudentId'

Posted 18 March 2013 - 03:22 AM

soryyyy i didnt specify..lol here it is ..

.InsertCommand.ExecuteNonQuery()



it gives me the syntax errror when i run the program
Was This Post Helpful? 0
  • +
  • -

#4 andrewsw  Icon User is offline

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3253
  • View blog
  • Posts: 10,908
  • Joined: 12-December 12

Re: Syntax error(missing Operator) in query expression '@StudentId'

Posted 18 March 2013 - 03:22 AM

Parameter names cannot contain spaces.

This post has been edited by andrewsw: 18 March 2013 - 03:23 AM

Was This Post Helpful? 0
  • +
  • -

#5 VB ASRAAF007  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 87
  • Joined: 11-April 12

Re: Syntax error(missing Operator) in query expression '@StudentId'

Posted 18 March 2013 - 03:35 AM

Thanks Andrew.. :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1