ASP error when updating database

Discussion in 'Software' started by RexNoctis, May 27, 2006.

  1. RexNoctis

    RexNoctis Corporal

    Hi all,

    I have a problem in my code and I can't see where. I've been fighting with this most of the day now.

    The error message I get is:

    Must declare the scalar variable "@Caption".
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. ​

    The part of the code that is causing the error:

    Code:
           <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:photosConnection_Manual_INSERT_Statement %>" InsertCommand="INSERT INTO images(imageCaption, imageThumbnailURL, imageURL, imageOwner) VALUES (@Caption, @ThumbnailURL, @URL, @Owner)" SelectCommand="SELECT * FROM [images]">
            <UpdateParameters>
                <asp:ControlParameter Name="Caption" ControlID="TextBox1" PropertyName="Text" />
                <asp:ControlParameter Name="ThumbnailURL" ControlID="FormView1.InsertItemTemplate.InsertItemTemplate.txtCaption" PropertyName="Text" />
                <asp:ControlParameter Name="URL" ControlID="FormView1.InsertItemTemplate.InsertItemTemplate.txtCaption" PropertyName="Text" />
                <asp:ControlParameter Name="Name" ControlID="FormView1.InsertItemTemplate.InsertItemTemplate.txtName" PropertyName="Text" />
            </UpdateParameters>
            </asp:SqlDataSource>
    As far as I can see, the @Caption variable is being declared. The code seems identical (apart from variable names) to the code given at http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.sqldatasource.updateparameters.aspx

    I'm using Visual Web Developer Express Edition with ASP.NET 2.0. I get no errors at build time in the IDE.

    Like I said, I've been working on it most of the day and it's possible that it is something incredibly obvious that I can't see. Any help or ideas would be gratefully received. If you need any more information or code, please let me know.

    Cheers!
     
  2. Kodo

    Kodo SNATCHSQUATCH

    you have no update statement in your sqlDataSource. Change UpdateParameters to InsertParameters
     
  3. RexNoctis

    RexNoctis Corporal

    doh!!

    I knew it was going to be something simple, I think I've been staring at it too long!

    Kodo, I could kiss you right now!! (But I won't :) )

    Thanks!!
     

MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds