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

Sqldatasource is not working in Grid

11 Answers 247 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Joe
Top achievements
Rank 1
Joe asked on 24 Sep 2010, 02:48 PM
Hi,

the SQLdatasource is not working with the grid.  I have no code-behind just using the SQLdatasource object.

Here is the code:

I used several examples on this forum but have had no luck in firing these events.

Thank You,

<telerik:RadScriptManager ID="ScriptManager1" runat="server">
       </telerik:RadScriptManager>
       <telerik:RadGrid ID="rdgBudget" runat="server" AllowFilteringByColumn="True" AllowPaging="True"
           AllowSorting="True" DataSourceID="SEMBudgetSource" GridLines="None" Skin="Office2007"
           AllowAutomaticInserts="true" AllowAutomaticUpdates="true" OnItemDataBound="Budget_ItemDataBound">
           <MasterTableView AutoGenerateColumns="False" DataSourceID="SEMBudgetSource" CommandItemDisplay="Top"
               DataKeyNames="SEMBudgetId">
               <EditFormSettings>
                   <EditColumn CancelImageUrl="../Images/Cancel.gif" EditImageUrl="../Images/Edit.gif"
                       InsertImageUrl="../Images/Insert.gif" UniqueName="EditCommandColumn" UpdateImageUrl="../Images/Update.gif">
                   </EditColumn>
               </EditFormSettings>
               <Columns>
                   <telerik:GridEditCommandColumn UniqueName="EditCommandColumn" ButtonType="ImageButton" />
                   <telerik:GridBoundColumn DataField="SEMBudgetId" DataType="System.Int32" ReadOnly="True"
                       UniqueName="SEMBudgetId" Visible="false">
                   </telerik:GridBoundColumn>
                   <telerik:GridBoundColumn DataField="Customer" DefaultInsertValue="" HeaderText="Customer"
                       SortExpression="Customer" UniqueName="Customer">
                   </telerik:GridBoundColumn>
                   <telerik:GridBoundColumn DataField="MarginBudget" DataType="System.Decimal" DefaultInsertValue=""
                       HeaderText="SEM Budget" SortExpression="MarginBudget" UniqueName="MarginBudget"
                       DataFormatString="{0:C}" ItemStyle-HorizontalAlign="Right">
                       <ItemStyle HorizontalAlign="Right"></ItemStyle>
                   </telerik:GridBoundColumn>
                   <telerik:GridBoundColumn DataField="BudgetSpent" DataType="System.Decimal" DefaultInsertValue=""
                       HeaderText="Budget Spent" SortExpression="BudgetSpent" UniqueName="BudgetSpent"
                       ReadOnly="true" DataFormatString="{0:C}" ItemStyle-HorizontalAlign="Right">
                       <ItemStyle HorizontalAlign="Right"></ItemStyle>
                   </telerik:GridBoundColumn>
                   <telerik:GridBoundColumn DataField="BudgetStartDate" DataType="System.DateTime" DefaultInsertValue=""
                       HeaderText="Start Date" SortExpression="BudgetStartDate" UniqueName="BudgetStartDate">
                   </telerik:GridBoundColumn>
                   <telerik:GridBoundColumn DataField="BudgetEndDate" DataType="System.DateTime" DefaultInsertValue=""
                       HeaderText="End Date" SortExpression="BudgetEndDate" UniqueName="BudgetEndDate">
                   </telerik:GridBoundColumn>
                   <telerik:GridCheckBoxColumn DataField="BudgetIsActive" DataType="System.Boolean"
                       DefaultInsertValue="" HeaderText="BudgetIsActive" SortExpression="BudgetIsActive"
                       UniqueName="Active">
                   </telerik:GridCheckBoxColumn>
               </Columns>
           </MasterTableView>
           <ClientSettings DataBinding-EnableCaching="true">
               <DataBinding EnableCaching="True">
               </DataBinding>
           </ClientSettings>
       </telerik:RadGrid>
       <asp:SqlDataSource ID="SEMBudgetSource" runat="server" ConnectionString="<%$ ConnectionStrings:myconnection %>"
           SelectCommand="SELECT [Customer], [MarginBudget], [SEMBudgetId], [BudgetStartDate], [BudgetEndDate], [BudgetIsActive], [BudgetSpent] FROM [mytesttable] WHERE ([companyid] IS NOT NULL) ORDER BY [Customer]"
           InsertCommand="INSERT INTO mytesttable(Customer, MarginBudget, BudgetStartDate, BudgetEndDate, BudgetIsActive) VALUES (@Customer, @Budget, @StartDate, @EndDate, @Active)"
           UpdateCommand="UPDATE mytesttable SET Customer = @Customer, MarginBudget = @Budget, BudgetStartDate = @StartDate, BudgetEndDate = @EndDate, BudgetIsActive = @Active WHERE (SEMBudgetId = @BID)">
           <UpdateParameters>
               <asp:Parameter Name="Customer" Type="String" />
               <asp:Parameter Name="Budget" Type="Decimal" />
               <asp:Parameter Name="StartDate" Type="DateTime" />
               <asp:Parameter Name="EndDate" Type="DateTime" />
               <asp:Parameter Name="Active" Type="Boolean" />
               <asp:Parameter Name="BID" Type="Int32" />
           </UpdateParameters>
           <InsertParameters>
               <asp:Parameter Name="Customer" Type="String" />
               <asp:Parameter Name="Budget" Type="Decimal" />
               <asp:Parameter Name="StartDate" Type="DateTime" />
               <asp:Parameter Name="EndDate" Type="DateTime" />
               <asp:Parameter Name="Active" Type="Boolean" />
           </InsertParameters>
       </asp:SqlDataSource>

11 Answers, 1 is accepted

Sort by
0
Pavlina
Telerik team
answered on 24 Sep 2010, 04:30 PM
Hi Joe,

Please review the online resources below and let me know if they help you to achieve the desired functionality:
http://demos.telerik.com/aspnet-ajax/grid/examples/programming/net2datasourcecontrols/defaultcs.aspx
http://www.telerik.com/help/aspnet-ajax/grddeclarativedatasource.html

All the best,
Pavlina
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Joe
Top achievements
Rank 1
answered on 24 Sep 2010, 04:57 PM
Hi,

Still didn't work.  The only new thing I added was

ProviderName

 

="System.Data.SqlClient"

 

Please review the code I've attached.  I'm hoping it's me, but I don't think so.


Thanks,
0
Joe
Top achievements
Rank 1
answered on 26 Sep 2010, 12:10 PM
Hi,

Can someone assist.  I need the grid to work with the SQLSource Object.  The Select functionality works, however updating and inserting do not work.  I have attached the code.  

Can someone help me.  I'm trying to get this done.

Thank You
0
Pavlina
Telerik team
answered on 27 Sep 2010, 12:53 PM
Hi Joe,

I suggest that you examine the code library below which represents how to perform automatic operations (update/insert/delete) with SqlDataSource control:
Automatic operations with SqlDataSource control

Best wishes,
Pavlina
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Joe
Top achievements
Rank 1
answered on 27 Sep 2010, 02:41 PM
I've been through those avenues and used the examples provided.  This still doesn't work.  What am I doing wrong if anything or is there a problem with the grid.
0
Pavlina
Telerik team
answered on 28 Sep 2010, 11:44 AM
Hello Joe,

I reviewed the provided code but I am not able to find the source of the problem there. To help you further I will need to debug the page locally. Therefore I would ask you to open a formal support ticket and send us a runnable sample for further investigation.

Regards,
Pavlina
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Joe
Top achievements
Rank 1
answered on 28 Sep 2010, 12:56 PM
Hi,

Two things:

1. no code-behind that is the entire assocated code
2. My support description ran out I can't submitt a support ticket

What I did yesterday was created a test web page.  And got it working.  Now I need to recreate the webform in the application and see if it's an issue with the other controls.

Thank You,

0
Joe
Top achievements
Rank 1
answered on 28 Sep 2010, 04:10 PM
Finally figure out the issue.  The bind variables of the SQLDatasource have to match exactly the same as the grid.

For example:
The Variables contain @ must be identical to the grid datafields
UpdateCommand="UPDATE myclientcenter SET Customer = @Customer, MarginBudget = @MarginBudget, BudgetStartDate = @BudgetStartDate, BudgetEndDate = @BudgetEndDate, BudgetIsActive = @BudgetIsActive WHERE (SEMBudgetId = @SEMBudgetId)">
0
Pavlina
Telerik team
answered on 30 Sep 2010, 12:55 PM
Hi Joe,

I am glad that you have found a solution to your problem.

Sincerely yours,
Pavlina
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Jack
Top achievements
Rank 1
answered on 27 Sep 2018, 06:36 PM

When I have had this problem in the past it is almost always related to the datafield names in my grid not matching up with my sqlDataSource Parameters. If the names all match the next thing you can do is to confirm that the data types in your grid match the data types of your parameters and that the data types of your parameters match the data types in your table. I have also found that checking for an error in the ItemInserted command can help point you in the right direction. For a grid called rgLeads you could do something like this

 

Private Sub rgLeads_ItemInserted(sender As Object, e As GridInsertedEventArgs) Handles rgLeads.ItemInserted
        If Not e.Exception Is Nothing Then
            e.ExceptionHandled = True
        End If
    End Sub

I then put a breakpoint inside of the If and review the value of e by hovering my mouse over it. What you put inside of the If really does not matter just anything that you can put a break point on. I am sure there is a better way but this works for me.

0
Tsvetomir
Telerik team
answered on 28 Sep 2018, 12:26 PM
Hi Jack,

Thank you for sharing your ideas with the community on what to check first when an issue related to the Declarative Data Binding is encountered.

As a side note, when in debug mode, you can make use of the QuickWatch tool which could be used to observe variables and expressions. To open the Watch window, choose  Debug > Windows > Watch.

Kind regards,
Tsvetomir
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Grid
Asked by
Joe
Top achievements
Rank 1
Answers by
Pavlina
Telerik team
Joe
Top achievements
Rank 1
Jack
Top achievements
Rank 1
Tsvetomir
Telerik team
Share this question
or