Friday, February 24, 2012

Error "Incorrect syntax near (." when doing Update() from code, VB

Hi all

My error is as follows:

Incorrect syntax near '('.
Line 27: acceptOrDeclineFriendship.UpdateParameters.Add("Response", answer)
Line 28: acceptOrDeclineFriendship.UpdateParameters.Add("FriendID", friend_id)
Line 29: acceptOrDeclineFriendship.Update()
Line 30:
Line 31: End Sub

Bear with me... I have a page where i use a repeater control to list users who have requested to be friends with the currently online user. The 'getFriendRequests' query looks like this:

SelectCommand="SELECT * FROM Friends, UserDetails WHERE (Friends.UserID = UserDetails.UserID) AND (FriendID = @.UserID) AND (ApprovedByFriend = 'False') ORDER BY Friends.Requested DESC"
This works.

Within each repeater template, there are 2 buttons, 'Accept' or 'Decline', like this:

 <asp:Repeater ID="Repeater1" runat="server" DataSourceID="getFriendRequests"> <ItemTemplate> (other stuff like avatar and username etc) <asp:Button ID="accept" runat="server" Text="Accept" commandName="Accept" commandArgument='<%#Eval("UserID")%>' onCommand="Accept_Decline_Friends"/> <asp:Button ID="decline" runat="server" Text="Decline" commandName="Decline" commandArgument='<%#Eval("UserID")%>' onCommand="Accept_Decline_Friends"/> </ItemTemplate> </asp:Repeater>

The code-behind (VB) which deals with this is as follows:

Protected Sub Accept_Decline_Friends(ByVal senderAs Object,ByVal eAs CommandEventArgs)'retrieve id of requestee and the answer accept/declineDim friend_idAs String = e.CommandArgument.ToStringDim answerAs String = e.CommandName.ToString'add the parameters acceptOrDeclineFriendship.UpdateParameters.Add("Response", answer) acceptOrDeclineFriendship.UpdateParameters.Add("FriendID", friend_id) acceptOrDeclineFriendship.Update()End Sub

Since the buttons are being created dynamically, this is how i track 1. the response from the currently logged in user 'Accept/Decline' and 2. who they are responding to (by their uniqueid)

This relates to a sqlDataSource on my .aspx page like this:

<!-- update query when user has accepted the friendship --> <asp:SqlDataSource ID="acceptOrDeclineFriendship" runat="server" ConnectionString="<%$ xxx%>" UpdateCommand="UPDATE Friends SET (ApprovedByFriend = @.Response) WHERE (FriendID = @.UserID) AND (UserID = @.FriendID)"> <UpdateParameters> <asp:ControlParameter Name="UserID" ControlID="userIdValue" /> </UpdateParameters> </asp:SqlDataSource>

Which is meant to update my 'Friends' table to show that 'ApprovedByFriend' (the logged in user) is either 'Accept' or 'Decline', and record who's request was responded to.

I hope this is clear, just trying to suppy all of the information! The error appears to be saying that I have an issue with my code-behind, where i am telling the sqlDataSource above to UPDATE. What I can say is that for each button in the repeater, the 2 variables 'friend_id' and 'answer' are picking up the correct values.

Can anyone see any obvious problems here? Any help is very much appreciated as i am well and truley stuck!


Hi all

after all that I figured out it was a simple syntax issue.

UpdateCommand="UPDATE Friends SET ApprovedByFriend = @.Response WHERE (FriendID = @.UserID) AND (UserID = @.FriendID)">
I had some brackets around the SET conditionEmbarrassed

No comments:

Post a Comment