【解決方法】このエラーを解決する方法 – 「同じパラメーター タイプで呼び出されるメンバーが既に定義されています」


私のコードでこれらのエラーが発生しています。

Type 'APP1.Views.Home.Chart1' already defines a member called 'Page_Load' with the same parameter types

Type 'APP1.Views.Home.Chart1' already defines a member called 'ConvetDataTableToString'; with the same parameter types

私のコードは

C#
namespace APP1.Views.Home
{
    public partial class Chart1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
        }

        public string ConvertDataTabletoString()
        {
            DataTable dt = new DataTable();
            using (SqlConnection con = new SqlConnection(Data Source=ABHISHEK; Initial Catalog=Experiment; Integrated Security=true;))
 {
                using (SqlCommand cmd = new SqlCommand("select title=Salary, Emp = Name, Sal = Salary from SALARY", con))
                {
                    // Connection Open
                    con.Open();
                    SqlDataAdapter da = new SqlDataAdapter(cmd);
                    da.Fill(dt);
                    System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
                    List<Dictionary<string,>> rows = new List<Dictionary<string,>>();
                    Dictionary<string,> row;
                    foreach (DataRow dr in dt.Rows)
                    {
                        row = new Dictionary<string,>();
                        foreach (DataColumn col in dt.Columns)
                        {
                            row.Add(col.ColumnName, dr[col]);
                        }
                        rows.Add(row);
                    }
                    return serializer.Serialize(rows);
                }
            }
        }
    }
}

解決策 1

解決:
MVC プロジェクトの共有フォルダーに同じ名前のメソッドが既にありました。 共有フォルダーのメソッド名を次のように変更しました。

C#
public string ConvertDataTabletoStringShow()
       { 
       }

You can also give it another name, like

public String ConvertData()
       {
       } 

#HappyCoding!

解決策 2

Visual Studio コードでは、クラス メソッドの名前を手動で変更することはできません。 メソッド名を右クリックして「シンボルの名前を変更」を選択すると、問題は解決します。

コメント

タイトルとURLをコピーしました