过程或函数Event_Update指定了太多参数

时间:2017-05-28 03:07:42

标签: c# sql procedure

我在尝试使用c#code

中的过程函数更新表事件时收到错误消息Dim wsData As Worksheet, wsOutput As Worksheet Dim keyRefs As Object, dupes As Object Dim keyF As String, keyL As String Dim i As Long, j As Long Dim data As Variant, output() As Variant, r As Variant Dim dupesFound As Boolean 'Set application values temporarily. With Application .Calculation = xlCalculationManual .EnableEvents = False .ScreenUpdating = False End With 'Assign worksheet object. Set wsData = Worksheets("Sheet1") On Error Resume Next Set wsOutput = Sheets("Duplicate Data") On Error GoTo 0 If Not wsOutput Is Nothing Then wsOutput.Cells.Clear Else ThisWorkbook.Sheets.Add(After:=wsData).Name = "Duplicate Data" Set wsOutput = ActiveSheet End If 'Read data into array. With wsData data = .Range(.Cells(4, "A"), _ .Cells(.Rows.Count, "A").End(xlUp)) _ .Resize(, 23).Value2 End With 'Gather the non-duplcate index numbers. Set keyRefs = CreateObject("Scripting.Dictionary") Set dupes = CreateObject("Scripting.Dictionary") For i = 1 To UBound(data, 1) keyF = CStr(data(i, 1)) If Not keyRefs.Exists(keyF) Then keyRefs.Add keyF, i Else If Not dupesFound Then dupesFound = True keyL = CStr(data(i, 1)) & "|L" If Not dupes.Exists(keyF) Then dupes.Add keyF, keyRefs(keyF) dupes.Add keyL, i Else dupes(keyL) = i End If End If Next 'Read each unique index from data array to output array, 'and write to sheet. If dupesFound Then 'this tests if you have any duplicates ReDim output(1 To dupes.Count, 1 To UBound(data, 2)) i = 1 For Each r In dupes.items For j = 1 To UBound(data, 2) output(i, j) = data(r, j) Next i = i + 1 Next With wsOutput .Range("A3:V3").Value = wsData.Range("A3:V3").Value2 .Range("A4").Resize(UBound(output, 1), UBound(output, 2)).Value = output With .Sort .SortFields.Clear .SortFields.Add Key:=wsOutput.Range("A3"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal .SetRange wsOutput.Range("A3").Resize(UBound(output, 1) + 1, UBound(output, 2)) .Header = xlYes .MatchCase = False .Orientation = xlTopToBottom .SortMethod = xlPinYin .Apply End With End With Else MsgBox "No duplicates found." End If 'Reset application values. With Application .Calculation = xlCalculationAutomatic .EnableEvents = True .ScreenUpdating = True End With

更新程序

Procedure or function Event_Update has too many arguments specified.

活动表

create procedure Event_Update
@id int,
@image varchar(50),
@title varchar(255),
@description varchar(255),
@date date

as

begin
update event set image = @image,title=@title,description=@description,event_date=@date where id=@id
end

C#代码

create table event(
id int identity(1,1) primary key,
image varchar(50) not null,
title varchar(255) not null,
description varchar(255) not null,
event_date date not null
)

1 个答案:

答案 0 :(得分:0)

cmd是全局变量?在cmd.Parameters方法中清除update

public void update(int id,string title, string image, string events, string date)
{
    cmd.Parameters.Clear();
    cmd.CommandText = "Event_Update";
    cmd.CommandType = CommandType.StoredProcedure;
    cmd.Parameters.AddWithValue("@id", id);
    cmd.Parameters.AddWithValue("@title", title);
    cmd.Parameters.AddWithValue("@image", image);
    cmd.Parameters.AddWithValue("@description", events);
    cmd.Parameters.AddWithValue("@date", date);
    cmd.ExecuteNonQuery();
}