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

Unable to Update Grid

1 Answer 16 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Karl
Top achievements
Rank 1
Karl asked on 03 Oct 2013, 07:36 PM
On a "Save" command, I'm trying to update multiple edited rows on an Excel like grid, the columns of which look like this:
<Columns>               
    <telerik:GridNumericColumn DataField="CarID" DataType="System.Int32" HeaderText="ID"
        SortExpression="CarID" UniqueName="CarID" AutoPostBackOnFilter="true" CurrentFilterFunction="EqualTo" HeaderStyle-Width="100" ItemStyle-Width="100" FilterControlWidth="60" ReadOnly="false"/>
    <telerik:GridBoundColumn DataField="CarMake" DataType="System.String" HeaderText="Car Make"
        SortExpression="CarMake" UniqueName="CarMake" AutoPostBackOnFilter="true" CurrentFilterFunction="Contains" HeaderStyle-Width="120" ItemStyle-Width="120" FilterControlWidth="80" />
    <telerik:GridBoundColumn DataField="CarModel" DataType="System.String" HeaderText="Car Model"
        SortExpression="CarModel" UniqueName="CarModel" AutoPostBackOnFilter="true" CurrentFilterFunction="Contains" HeaderStyle-Width="120" ItemStyle-Width="120" FilterControlWidth="80" />
    <telerik:GridBoundColumn DataField="CarTrim" DataType="System.String" HeaderText="Car Trim"
        SortExpression="CarTrim" UniqueName="CarTrim" AutoPostBackOnFilter="true" CurrentFilterFunction="Contains" HeaderStyle-Width="200" ItemStyle-Width="200" FilterControlWidth="160"/>
    <telerik:GridNumericColumn DataField="CarYear" DataType="System.Int32" HeaderText="Car Year"
        SortExpression="CarYear" UniqueName="CarYear" AutoPostBackOnFilter="true" CurrentFilterFunction="EqualTo" HeaderStyle-Width="100" ItemStyle-Width="100" FilterControlWidth="60" />
</Columns>

Here's my "Save" command:
Case "Save"
    For Each editedItem As GridEditableItem In RadGridViewExcelGridTest.EditItems
        Dim newValues As Hashtable = New Hashtable
        'The GridTableView will fill the values from all editable columns in the hash
        e.Item.OwnerTableView.ExtractValuesFromItem(newValues, editedItem)
        SqlDataSourceExcelGridTest.UpdateCommandType = SqlDataSourceCommandType.StoredProcedure
        SqlDataSourceExcelGridTest.UpdateCommand = "spExcelGridTestUpdateTable"
        SqlDataSourceExcelGridTest.UpdateParameters.Add(New Parameter("CarID", DbType.Int32))
        SqlDataSourceExcelGridTest.UpdateParameters.Add(New Parameter("CarMake", DbType.String))
        SqlDataSourceExcelGridTest.UpdateParameters.Add(New Parameter("CarModel", DbType.String))
        SqlDataSourceExcelGridTest.UpdateParameters.Add(New Parameter("CarTrim", DbType.String))
        SqlDataSourceExcelGridTest.UpdateParameters.Add(New Parameter("CarYear", DbType.Int32))
        SqlDataSourceExcelGridTest.Update()
        editedItem.Edit = False
    Next

And my stored procedure looks like this:
ALTER PROCEDURE [dbo].[spExcelGridTestUpdateTable]
    -- Add the parameters for the stored procedure here
    @CarID int,
    @CarMake varchar(100),
    @CarModel varchar(100),
    @CarTrim varchar (100),
    @CarYear int
 
AS
BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;
 
        UPDATE [dbo].[TestTable_Cars]
            SET CarMake=@CarMake, CarModel=@CarModel, CarTrim=@CarTrim, CarYear=@CarYear
            WHERE CarID=@CarID
 
END

The error that I'm getting is Procedure or function spExcelGridTestUpdateTable has too many arguments specified. Most folks getting this error seem to simply have a typo when it comes to one of the parameter names, but I've checked and everything seems to line up. If I execute the SP from SQLServer and provide the parameters (or pass NULL params), the SP runs fine.

UPDATE (10/4/2013 1:09PM): Adding this line before I start adding parameters prevents the error, but the table still doesn't get updated:
SqlDataSourceExcelGridTest.UpdateParameters.Clear()

1 Answer, 1 is accepted

Sort by
0
Konstantin Dikov
Telerik team
answered on 08 Oct 2013, 12:02 PM
Hello Karl,

Please refer to our code library "Excel look and feel for RadGrid" for this scenario and the used approach for updating the database.

I could also suggest you to take a look at the following MSDN article about  "SqlParameterCollection.AddWithValue Method" that in my opinion will solve the issue in your scenario.

Hope that helps.


Regards,
Konstantin Dikov
Telerik
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 the blog feed now.
Tags
Grid
Asked by
Karl
Top achievements
Rank 1
Answers by
Konstantin Dikov
Telerik team
Share this question
or