gpt4 book ai didi

c# - 已经定义了一个使用相同参数类型调用的成员 c#

转载 作者:行者123 更新时间:2023-11-30 13:43:47 25 4
gpt4 key购买 nike

正如标题所说,我有这个错误already defined a member called with the same parameter types c#

我研究了多个相同的问题,但它们都说明了为什么会发生以及如何处理(将方法名称更改为其他名称)但我不想将方法名称更改为其他名称,因为它是相同的方法但是参数不同,所以我只想绕过它。

我有两种方法:

public static List<int> Lista(int vrDok)
{
List<int> list = new List<int>();
using (FbConnection con = new FbConnection(M.Baza.connectionKomercijalno2018))
{
con.Open();
using (FbCommand cmd = new FbCommand("SELECT BRDOK FROM DOKUMENT WHERE VRDOK = @VrDok ORDER BY DATUM ASC", con))
{
cmd.Parameters.AddWithValue("@VrDok", vrDok);

FbDataReader dr = cmd.ExecuteReader();

while (dr.Read())
{
list.Add(Convert.ToInt32(dr[0]));
}
}
}
return list;
}
public static List<int> Lista(int magacinId)
{
List<int> list = new List<int>();
using (FbConnection con = new FbConnection(M.Baza.connectionKomercijalno2018))
{
con.Open();
using (FbCommand cmd = new FbCommand("SELECT BRDOK FROM DOKUMENT WHERE MAGACINID = @MID ORDER BY DATUM ASC", con))
{
cmd.Parameters.AddWithValue("@MID", magacinId);

FbDataReader dr = cmd.ExecuteReader();

while (dr.Read())
{
list.Add(Convert.ToInt32(dr[0]));
}
}
}
return list;
}

如您所见,它们完全相同,但参数不同,这会给我带来错误。

我怎样才能绕过它?

最佳答案

Davide 的任何建议都会奏效。另一种选择是只使用一个采用 ID 和参数名称的方法,如下所示:

public static List<int> Lista(int id,string paramName)
{
List<int> list = new List<int>();
using (FbConnection con = new FbConnection(M.Baza.connectionKomercijalno2018))
{
con.Open();
using (FbCommand cmd = new FbCommand("SELECT BRDOK FROM DOKUMENT WHERE MAGACINID = @MID ORDER BY DATUM ASC", con))
{
cmd.Parameters.AddWithValue(paramName, id);

FbDataReader dr = cmd.ExecuteReader();

while (dr.Read())
{
list.Add(Convert.ToInt32(dr[0]));
}
}
}
return list;
}

因为这两种方法中的所有内容都是相同的,只是参数名称发生了变化。

关于c# - 已经定义了一个使用相同参数类型调用的成员 c#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50737606/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com