3

在“保存”命令中,我正在尝试更新类似 Excel 的网格上的多个已编辑行,其列如下所示:

<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" />

这是我的“保存”命令:

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

我的存储过程如下所示:

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

我得到的错误是Procedure or function spExcelGridTestUpdateTable has too many arguments specified。大多数收到此错误的人似乎只是在涉及其中一个参数名称时有一个错字,但我已经检查过,一切似乎都排成一行。如果我从 SQLServer 执行 SP 并提供参数(或传递 NULL 参数),SP 运行良好。

4

1 回答 1

1

尝试添加

SqlDataSourceExcelGridTest.UpdateParameters.Clear()

SqlDataSourceExcelGridTest.UpdateParameters.Add(New Parameter("CarID", DbType.Int32)) 
于 2013-10-03T21:42:00.377 回答