This is a migrated thread and some comments may be shown as answers.

Update to db not happening

1 Answer 83 Views
Grid
This is a migrated thread and some comments may be shown as answers.
David OBrien
Top achievements
Rank 1
David OBrien asked on 29 Jun 2012, 07:03 PM
I have a radgrid

<telerik:RadGrid ID="RadGrid1" GridLines="None" runat="server" AllowAutomaticDeletes="True" AllowSorting="True"
     PageSize="25" AllowAutomaticUpdates="True" AllowMultiRowEdit="False" AutoGenerateColumns="False"
     AllowPaging="True" DataSourceID="DataSource1" OnItemUpdated="RadGrid1_ItemUpdated"
     AllowFilteringByColumn="True" OnItemDeleted="RadGrid1_ItemDeleted"
     OnDataBound="RadGrid1_DataBound">
     <PagerStyle Mode="NextPrevAndNumeric"  Position="TopAndBottom" PageSizeLabelText="Rows Per Page:" />
     <MasterTableView Width="100%" CommandItemDisplay="TopAndBottom" DataSourceID="DataSource1" EditMode="InPlace" UseAllDataFields="True">
         <Columns>
             <telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="EditCommandColumn">
                 <ItemStyle CssClass="MyImageButton" />
             </telerik:GridEditCommandColumn>
             <telerik:GridBoundColumn    DataField="InstallCount"
                                         HeaderText="Install Count"
                                         SortExpression="InstallCount"
                                         UniqueName="InstallCount"
                                         ReadOnly="True">
             </telerik:GridBoundColumn>
             <telerik:GridBoundColumn    DataField="PackageName"
                                         HeaderText="Package Name"
                                         SortExpression="PackageName"
                                         UniqueName="PackageName"
                                         ReadOnly="True">
             </telerik:GridBoundColumn>
             <telerik:GridDropDownColumn DataField="ToBeTestedID"
                                         DataSourceID="SqlDataSource3"  
                                         HeaderText="To Be Tested"
                                         ListTextField="ToBeTested"
                                         ListValueField="ToBeTestedID"  
                                         UniqueName="ToBeTestedID"
             /> 
             <telerik:GridDropDownColumn DataField="StatusID"
                                         DataSourceID="SqlDataSource2"  
                                         HeaderText="Status"
                                         ListTextField="Status"
                                         ListValueField="StatusID"  
                                         UniqueName="StatusID"
             />                   
             <telerik:GridBoundColumn    DataField="LOB"
                                         HeaderText="Line Of Business"
                                         SortExpression="LOB"
                                         UniqueName="LOB"
                                         ReadOnly="False">
             </telerik:GridBoundColumn>
             <telerik:GridBoundColumn    DataField="AlliancePartner"
                                         HeaderText="Alliance Partner"
                                         SortExpression="AlliancePartner"
                                         UniqueName="AlliancePartner"
                                         ReadOnly="False">
             </telerik:GridBoundColumn>
             <telerik:GridBoundColumn    DataField="DslID"
                                         HeaderText="Dsl ID"
                                         SortExpression="DslID"
                                         UniqueName="DslID"
                                         ReadOnly="False">
             </telerik:GridBoundColumn>
             <telerik:GridBoundColumn    DataField="Contacts"
                                         HeaderText="Contacts"
                                         SortExpression="Contacts"
                                         UniqueName="Contacts"
                                         ReadOnly="False">
             </telerik:GridBoundColumn>
             <telerik:GridBoundColumn    DataField="EmailSentDate"
                                         HeaderText="Email Sent Date"
                                         SortExpression="EmailSentDate"
                                         UniqueName="EmailSentDate"
                                         ReadOnly="False">
             </telerik:GridBoundColumn>
         </Columns>
         <EditFormSettings>
            <FormTableItemStyle Wrap="False"></FormTableItemStyle>
             <FormCaptionStyle CssClass="EditFormHeader"></FormCaptionStyle>
             <FormMainTableStyle GridLines="None" CellSpacing="0" CellPadding="3" BackColor="White"
                 Width="100%" />
             <FormTableStyle CellSpacing="0" CellPadding="2" Height="110px" BackColor="White" />
             <FormTableAlternatingItemStyle Wrap="False"></FormTableAlternatingItemStyle>
             <EditColumn ButtonType="ImageButton"
                 UniqueName="EditCommandColumn1" CancelText="Cancel edit">
             </EditColumn>
             <FormTableButtonRowStyle HorizontalAlign="Right" CssClass="EditFormButtonRow"></FormTableButtonRowStyle>
         </EditFormSettings>
     </MasterTableView>
 </telerik:RadGrid>


populated from datasource1

<asp:SqlDataSource
        SelectCommand="SELECT InstallCount,PackageName,ToBeTestedID,ToBeTested,StatusID,Status,LOB,AlliancePartner,DslID,Contacts,EmailSentDate FROM AppFactory.dbo.WFCpackageinstalls"
        UpdateCommand="
            UPDATE AppFactory.dbo.WFCpackageinstalls SET
                [StatusID] = @StatusID,
                [ToBeTestedID] = @ToBeTestedID,
                [LOB] = @LOB,
                [AlliancePartner] = @AlliancePartner,
                [Contacts] = @Contacts,
                [EmailSentDate] = @EmailSentDate,
                [DslID] = @DslID
            WHERE [PackageName] = @PackageName"
        ConnectionString="<%$ ConnectionStrings:LC2ConnectionString %>"
        ProviderName="System.Data.SqlClient"
        ID="DataSource1"
        runat="server" >
        <UpdateParameters>
            <asp:Parameter Name="StatusID" Type="Int32" />
            <asp:Parameter Name="ToBeTestedID" Type="Int32" />
            <asp:Parameter Name="LOB" Type="String" />
            <asp:Parameter Name="AlliancePartner" Type="String" />
            <asp:Parameter Name="PackageName" Type="String" />
            <asp:Parameter Name="Contacts" Type="String" />
            <asp:Parameter Name="EmailSentDate" Type="String" />
            <asp:Parameter Name="DslID" Type="String" />
        </UpdateParameters>
     </asp:SqlDataSource>   
    <asp:SqlDataSource
        SelectCommand="SELECT StatusID, Status FROM AppFactory.dbo.lu_tbl_status"
        ConnectionString="<%$ ConnectionStrings:LC2ConnectionString %>"
        ProviderName="System.Data.SqlClient"
        ID="SqlDataSource2"
        runat="server"
     />
    <asp:SqlDataSource
        SelectCommand="SELECT ToBeTestedID, ToBeTested FROM AppFactory.dbo.lu_tbl_tobetested"
        ConnectionString="<%$ ConnectionStrings:LC2ConnectionString %>"
        ProviderName="System.Data.SqlClient"
        ID="SqlDataSource3"
        runat="server"
     />

inside I have two drop downs populated from lookup tables  from the queries above in datasource 2 and 3

The correct values are selected based on the actual values of the id columns in the main table.

So everything works except when I change a value for anything and save the row....
the message at the bottom says "Item Updated!" but the database is not being updated with any new values. It's aggravating.

the code behind

Imports Telerik.Web.UI
 
Partial Class AppFactory
    Inherits System.Web.UI.Page
        Private gridMessage As String = Nothing
 
        Protected Sub RadGrid1_DataBound(ByVal sender As Object, ByVal e As EventArgs)
            If Not String.IsNullOrEmpty(gridMessage) Then
                DisplayMessage(gridMessage)
            End If
        End Sub
 
        Protected Sub RadGrid1_ItemDeleted(ByVal source As Object, ByVal e As Telerik.Web.UI.GridDeletedEventArgs)
            If Not e.Exception Is Nothing Then
                e.ExceptionHandled = True
                SetMessage("Delete failed. Reason: " + e.Exception.Message)
            Else
                SetMessage("Item deleted!")
            End If
        End Sub
 
        Protected Sub RadGrid1_ItemUpdated(ByVal source As Object, ByVal e As Telerik.Web.UI.GridUpdatedEventArgs)
            If Not e.Exception Is Nothing Then
                e.KeepInEditMode = True
                e.ExceptionHandled = True
                SetMessage("Update failed. Reason: " + e.Exception.Message)
            Else
            SetMessage("Item updated! " + source.ToString)
            End If
        End Sub
 
        Protected Sub RadGrid1_ItemInserted(ByVal source As Object, ByVal e As Telerik.Web.UI.GridInsertedEventArgs)
            If Not e.Exception Is Nothing Then
                e.ExceptionHandled = True
                e.KeepInInsertMode = True
                SetMessage("Insert failed. Reason: " + e.Exception.Message)
            Else
                SetMessage("New product is inserted!")
            End If
        End Sub
 
        Private Sub DisplayMessage(ByVal text As String)
            RadGrid1.Controls.Add(New LiteralControl(String.Format("<span style='color:red'>{0}</span>", text)))
        End Sub
 
        Private Sub SetMessage(ByVal message As String)
            gridMessage = message
        End Sub
End Class



1 Answer, 1 is accepted

Sort by
0
Andrey
Telerik team
answered on 04 Jul 2012, 10:56 AM
Hi,

How you are verifying that the update is not performed over the datasource?

Additionally, you could try to regenerate the datasource control, sometimes there is a bug in Visual Studio which causes SqlDataSource control to not perform Update/Insert operations.

Give these suggestions a try and check whether the issue still replicates.

All the best,
Andrey
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Grid
Asked by
David OBrien
Top achievements
Rank 1
Answers by
Andrey
Telerik team
Share this question
or