none
update problem with linq to sql RRS feed

  • Question

  • I posted the question in this forum since I am wondering if I am missing something in my linq to sql code and/or possibly the control I am working with. I am thinking I might need to post this question in a C# forum?

    Since I am new to working with C# detailsview control 2010, I have the following question to ask. Right now I am trying to get a detailsview control to update one record in the database. I am using the smallest version of the code so I can make certain the update will work before I add more code. Right now in the new application, I have the first webform page entered by the user, they click the next button and they are directed to the second webform page. When the user is directed to the second webform page, the detailsview control for one record will be displayed.

    I want the record to update a record when the user clicks a button not contained within the detailsview control. However the update has not occurred. I have tried lots of different options but nothing has worked so far. For example, I read lots of sources that said I should not have a 'new' statement in the select. However if I leave out the 'new' part of the select statements, I get an error.

    What you do think I should do, have a update statement in the in the linq data source, use 2 different linq data sources, what do you think I should try to do to to make the code work.

    The following is my code so far:

    <asp:LinqDataSource ID="LinqDataSource1" runat="server" ContextTypeName="Support.AttDataContext"
            Select="new (Att_id, Prior_Cutoff_Date)"
            TableName="Attestations" Where="Att_id == @Att_id"
            EnableUpdate="True">
            <UpdateParameters>
                <asp:SessionParameter Name="Att_id" SessionField="AttID" />
            </UpdateParameters>
            <WhereParameters>
                <asp:SessionParameter Name="Att_id" SessionField="AttID" Type="Int32" />
            </WhereParameters>
        </asp:LinqDataSource>

     <asp:DetailsView ID="DetailsView1" runat="server" Height="50px" Width="125px" EnableModelValidation="False"
            AutoGenerateRows="False" DataSourceID="LinqDataSource1" BorderStyle="Solid" HorizontalAlign="Center"
            DefaultMode="Edit">
            <Fields>
                <asp:TemplateField HeaderText="Att ID">
                    <ItemTemplate>
                        <asp:TextBox ID="TextBoxAttid" runat="server" Text='<%# Eval("Att_id") %>'
                            BorderStyle="None"></asp:TextBox>
                    </ItemTemplate>
                </asp:TemplateField>
               
                <asp:TemplateField HeaderText="Prior Cutoff Date" SortExpression="Prior_Cutoff_Date">
                    <ItemTemplate>
                        <asp:Label ID="Label1" runat="server" Text='<%# Bind("Prior_Cutoff_Date") %>'></asp:Label>
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Prior_Cutoff_Date") %>'></asp:TextBox>
                    </EditItemTemplate>
                  
                </asp:TemplateField>
            </Fields>
        </asp:DetailsView>

    protected void Button_Click(object sender, EventArgs e)
            {
                 DetailsView1.DataBind();
             }



    Thursday, November 17, 2011 10:11 PM

Answers