Friday, March 23, 2012

Incorrect Syntax error?

I am getting the following error when attempting to call a certain function:

"Incorrect Syntax near spListPrograms, Line 1"

Here is the sproc:

ALTER PROCEDUREspListPrograms

@.parentIDint= 0

AS

SELECTpwbsID, pwbsTitleFROMProgramWBSWHEREpwbsParent = @.parentID

It is being called from this function:

PublicSharedFunction ListProgramChildNodes(OptionalByVal parentIDAsInteger = 0)As SqlDataReader

Dim cmdAsNew SqlCommand("spListPrograms", strConn)

cmd.Parameters.AddWithValue("@.parentID", parentID)

Try

strConn.Open()

Return cmd.ExecuteReader(CommandBehavior.CloseConnection)

Catch eAs SqlException

Dim errorMessagesAsString =""

Dim iAsInteger

For i = 0To e.Errors.Count - 1

errorMessages +="Index #" & i.ToString() & ControlChars.NewLine _

&"Message: " & e.Errors(i).Message & ControlChars.NewLine _

&"LineNumber: " & e.Errors(i).LineNumber & ControlChars.NewLine _

&"Source: " & e.Errors(i).Source & ControlChars.NewLine _

&"Procedure: " & e.Errors(i).Procedure & ControlChars.NewLine

Next i

MsgBox(errorMessages)

Finally

strConn.Close()

EndTry

EndFunction

The sproc works just fine when I execute it from the database directly in SQl Express. What could cause an incorrect syntax error? There's hardly any syntax there for an error to occur Thanks for any help you can give me.

Try specifying that the commandtype is a stored procedure and see if that takes care of your problem:
cmd.CommandType = CommandType.StoredProcedure
|||Thanks, I did finally figure that out after about 3 hours of pulling my hair out. Must need sleep or something...

No comments:

Post a Comment