I have a GridView with an Update button. I want to update a field in the database but I think the ‘@’ in the code below is causing the problem in my ASP .NET page. What can be done within the grid or in the update (UpdateCommand) statement? Note, I get an Ora 00936 error.
<asp:SqlDataSource ID="dsBooks" runat="server"
ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT OBJECTID, TRACT, GIS_ACRES, COMMENTS, PDF_STORAGE FROM CampusDev.CU_POLY ORDER BY OBJECTID"
UpdateCommand="UPDATE CampusDev.CU_POLY SET COMMENTS='just atest' WHERE OBJECTID=@OBJECTID"
The “:OBJECTID” in Oracle parlance is a Bind Variable.
I’m ignorant of asp.net semantics, but you will want to use bind variables here. This link should provide a more complete explanation, but basically it’s this:
Then execute your command.
Always use bind variables where possible in production code – it allows Oracle to avoid hard parsing of the SQL statement.
Also, the name of the Bind Variable is unimportant to Oracle. The order in which it appears is the important aspect. You could just as easily say
with the same effect.