Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Am getting these errors in my code,

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

my code is
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);
                }
            }
        }
    }
}
Posted
Updated 1-Jan-23 1:31am
v3
Comments
Abhishek Jaiswall 18-Aug-14 4:51am    
code is in C#
Thomas Daniels 18-Aug-14 4:55am    
The error explains what's wrong; do you have the same methods defined in another file? That's possible because your class is partial.
Abhishek Jaiswall 18-Aug-14 5:15am    
I have solved this myself, meanwhile thanks! :)
Prasad Avunoori 18-Aug-14 5:33am    
Hi Abhishek,
Post your solution. This could be helpful for other members too.
Abhishek Jaiswall 18-Aug-14 5:47am    
Hey!
okay :)

Solution:
I had already a method with the same name in my Shared Folder in MVC Project. I did change the method name in shared folder as:

C#
public string ConvertDataTabletoStringShow()
       { 
       }

You can also give it another name, like

public String ConvertData()
       {
       } 

#HappyCoding!
 
Share this answer
 
In visual Studio code, you can not rename class methods manualy. If you right click on the method name, select "Rename symbol", the issue goes away.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900