ASP.NET problem GridView and UpdateParameters

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • RobertTheProgrammer
    New Member
    • Aug 2007
    • 58

    ASP.NET problem GridView and UpdateParameters

    Hi all,

    I'm really stuck here. I've got a GridView on my page and I want to use the update features to-- well, update. Here is my block of code in the SqlDataSource section:

    Code:
            <asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionStringTraining %>"
                ProviderName="<%$ ConnectionStrings:ConnectionStringTraining.ProviderName %>"
                SelectCommand="SELECT training_unit_id, training_unit_name, training_unit_type, training_unit_frequency FROM training_units order by training_unit_name"
                UpdateCommand="UPDATE training_units SET training_unit_name = @training_unit_name, training_unit_type = @training_unit_type, training_unit_frequency = @training_unit_frequency WHERE training_unit_id = @training_unit_id">
                    <UpdateParameters>
                        <asp:Parameter Name="training_unit_name" Type="String" />
                        <asp:Parameter Name="training_unit_type" Type="String" />
                        <asp:Parameter Name="training_unit_frequency" Type="String" />
                        <asp:Parameter Name="training_unit_id" Type="Int32" />
                    </UpdateParameters>
            </asp:SqlDataSource>
    I can open the GridView just fine and I can edit it just fine, but when I do the update, I get the error message: "Must declare variable '@training_unit _name'." and, of course, nothing is stored.

    What am I doing wrong? I've been working on this for hours and I keep going in circles. All the documentation I've found indicates this is perfectly legitimate.

    Thanks in advance.

    Robert Porter
  • RobertTheProgrammer
    New Member
    • Aug 2007
    • 58

    #2
    Hi again,

    As a follow-up to my own question, I got it working (sort of) by removing the variable tags (the @ references) and just using the "?" symbols. Very strange.

    Of course, now it's not updating my bound variables, but that's another topic.

    Robert

    Comment

    • RobertTheProgrammer
      New Member
      • Aug 2007
      • 58

      #3
      *Sigh!* I've got a lot to learn. I've just discovered TableAdapters. That solves yet another problem.

      Robert

      Comment

      Working...