none
Error when querying a SQL server compact edition with VB.net

    Question

  • I am using SQLCE as the back end of an application I am writing. I have various tables and I am trying to return a single value and eventually place it in either a label or a text box for use in other application layer calculations. Unfortunately I can not get the query to work and having spent significant time looking around the forums I can't find an answers. Basically I want to look in one table and return one of the field values where another field equals a value in a text box (the field is unique) my current code is below and the error I am getting is "There was an error parsing the query. [ Token line number = 1,Token line offset = 91,Token in error = , ]". I have checked the select statement in the query builder and that is bring back the correct resut 

    ****************************************************************************

      Dim cmd As New SqlCeCommand
                cmd.Connection = conn


                conn.Open()

                cmd = New SqlCeCommand()


                cmd.CommandText = "SELECT (OverallCostPerHour) FROM Tbl_VehicleMasterfile WHERE (Vehicle_Type = @VEHICLETYPE), conn"





                cmd.Parameters.Add("@VEHICLETYPE", SqlDbType.NVarChar, 20)

                cmd.Parameters("@VEHICLETYPE").Value = CBEquipment_Type1.SelectedValue
                cmd.Connection = conn


                If conn.State = ConnectionState.Closed Then
                    conn.Open()

                End If

                Dim returnvalue As SqlCeDataReader = cmd.ExecuteReader(CommandBehavior.SingleResult)


           
            Catch ex As Exception
                TextBox1.Text = (ex.Message)
                ' MsgBox(ex.Message)
            End Try

    Friday, March 21, 2014 5:50 PM

Answers

  • cmd.CommandText = "SELECT (OverallCostPerHour) FROM Tbl_VehicleMasterfile WHERE (Vehicle_Type = @VEHICLETYPE), conn"

    Hello,

    I guess by mistake you copy then part ", conn" from a constructor code into your SQL statement; just remove it =>

    cmd.CommandText = "SELECT OverallCostPerHour FROM Tbl_VehicleMasterfile WHERE Vehicle_Type = @VEHICLETYPE"

    And all those brackets () are "MS Access" style; no need for them.


    Olaf Helper

    [ Blog] [ Xing] [ MVP]


    Saturday, March 22, 2014 6:20 AM

All replies

  • cmd.CommandText = "SELECT (OverallCostPerHour) FROM Tbl_VehicleMasterfile WHERE (Vehicle_Type = @VEHICLETYPE), conn"

    Hello,

    I guess by mistake you copy then part ", conn" from a constructor code into your SQL statement; just remove it =>

    cmd.CommandText = "SELECT OverallCostPerHour FROM Tbl_VehicleMasterfile WHERE Vehicle_Type = @VEHICLETYPE"

    And all those brackets () are "MS Access" style; no need for them.


    Olaf Helper

    [ Blog] [ Xing] [ MVP]


    Saturday, March 22, 2014 6:20 AM
  • Olaf

    Thank you so much that worked absolutely perfectly

    Saturday, March 22, 2014 8:03 PM