Reputation: 2499
Just as title says i have this error already defines a member called with the same parameter types c#
I have looked into multiple same questions but they all tells why does it happens and how to deal with it (change name of method to some other) BUT i do not want to change method name to something other because it is same method but with different parameter so i just want to bypass it.
Here are 2 methods i have:
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;
}
So as you can see they are totally identical but with different parameter and it drops me error.
How can i bypass it?
Upvotes: 4
Views: 15854
Reputation: 715
It gives error because the method signature is the same
The parameters name doesn't matter only the method name and the parameters type are considered.
You can resolve by changing the name of one method (ex. ListaByVrDok, ListaByMagician)
Upvotes: 8
Reputation: 128
Any of Davide suggestions will work. Another options is to do just have one method that takes the ID and the Parameter Name like so:
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;
}
Since everything in both methods are the same and just which parameter name changes.
Upvotes: 6