dcsimg
Results 1 to 3 of 3

Thread: [RESOLVED] Parametr query fails

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2006
    Posts
    313

    Resolved [RESOLVED] Parametr query fails

    Code:
     Private Sub cmdSearch_Click(sender As Object, e As EventArgs) Handles cmdSearch.Click
    
            Dim MyDays As Integer
    
            Integer.TryParse(txtDays.Text, MyDays)
    
            'EXECUTE QUERY AND POPULATE GRID
    
    
            SQL.ExecQuery("SELECT WorkOrderID, MachineNumber, WorkorderDate , Priority, Problem, Description, EmployeeName FROM workorders" &
                         " WHERE (WorkorderDate Is Not NULL) And (WorkorderDate <= {fn NOW() } - MyDays ) AND WOClosed = 'false';")
    
            LoadGrid()
    
        End Sub
    This my code for running the query where I have entered a number for the variable" MYDays".
    I am entering an integer number say 7 and it fails with this error.

    Code:
    System.InvalidCastException: 'Conversion from string "ExceQuery Error: 
    Invalid colum" to type 'Integer' is not valid.'
    System.InvalidCastException
    Inner Exception 1:
    FormatException: Input string was not in a correct format.
    Now if I change it to this it runs fine
    Code:
       SQL.ExecQuery("SELECT WorkOrderID, MachineNumber, WorkorderDate , Priority, Problem, Description, EmployeeName FROM workorders" &
                         " WHERE (WorkorderDate Is Not NULL) And (WorkorderDate <= {fn NOW() } - 7) AND WOClosed = 'false';")
    I do not know how to fix this..
    Thanks

  2. #2
    Frenzied Member
    Join Date
    Dec 2014
    Location
    VB6 dinosaur land
    Posts
    1,153

    Re: Parametr query fails

    Code:
            SQL.ExecQuery("SELECT WorkOrderID, MachineNumber, WorkorderDate , Priority, Problem, Description, EmployeeName FROM workorders" &
                         " WHERE (WorkorderDate Is Not NULL) And (WorkorderDate <= {fn NOW() } - " & MyDays.ToString & " ) AND WOClosed = 'false';")
    If you had really used a parameter as the title suggested rather than string concatenation, this wouldn't have been an issue.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2006
    Posts
    313

    Re: Parametr query fails

    thank you

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width