What is this error message mean? CS0115

BenTam 1,721 Reputation points
2024-11-02T09:17:01.64+00:00

Dear all,

How to fix the error: CS0115 'Student_Form.Dispose(bool)': no suitable method found to override NewTims C:\Users\benta\source\repos\NewTims\Student_Form.Designer.cs 14

using System.Data;
using System.Data.SqlClient;

namespace NewTims
{
    public partial class Student_Form
    {
        private static int nStudentID = 0; //Declare it as a private field and use the static modifier
        private static string cEngName = "0";

        public Student_Form()
        {
            InitializeComponent();
            RetrieveData();
        }

        public void RetrieveData()
        {
            bool bDesc = false;
            string cConnectionString = "Data Source=(local); Initial Catalog=Tims; Integrated Security=True";

            using (SqlConnection connection = new SqlConnection(cConnectionString))
            {
                connection.Open(); // Ensure the connection is opened before using it

                string PreSelectQry = "Select top 1 StudentID, EngName from student where EngName >= '"
                    + cEngName + "' and studentid > " + nStudentID.ToString()
                    + " order by " + (nStudentID == 0 ? "StudentID" : "EngName, StudentID");
                SqlCommand command = new SqlCommand(PreSelectQry, connection);
                SqlDataAdapter adapter = new SqlDataAdapter(command);
                DataSet ds = new DataSet();
                adapter.Fill(ds, "PreStudent");
                DataTable dt = ds.Tables[0];
                if (dt.Rows.Count > 0)
                {
                    nStudentID = dt.Rows[0].Field<int>("StudentID");
                    string cEngName = dt.Rows[0].Field<string>("EngName").ToString();
                }
                string SelectQuery = @"select Top 1 s.*, o.CourseID, o.SubjectID, g.EngName as GroupName, c.SubjectID"
                    + " from student s"
                    + " left Join student g on s.memberOf = g.studentid"
                    + " left join studentCourse c on s.studentid = c.studentid"
                    + " left join course o on c.CourseID = o.CourseID"
                    + " where s.EngName >= '" + cEngName
                    + "' order by s.EngName" + (bDesc ? " desc" : "").ToString()
                    + ", s.StudentID" + (bDesc ? " desc" : "").ToString();

                //and s.StudentID > "+nStudentID.ToString()

                command = new SqlCommand(SelectQuery, connection);
                adapter = new SqlDataAdapter(command);
                ds = new DataSet();
                adapter.Fill(ds, "Student");

                dt = ds.Tables["Student"];
                if (dt.Rows.Count > 0)
                {
                    DataRow r = dt.Rows[0];
                    cEngName = r.Field<string>("EngName").Trim();
                    string Sex = r.Field<string>("Sex");
                    if (Sex.Trim() != "O")
                    {
                        int iFirstBlank = cEngName.IndexOf(" ", 0);
                        Surname_textBox.Text = cEngName.Substring(0, iFirstBlank);
                        Surname_textBox.Visible = true;
                        GivenName_textBox.Text = cEngName.Substring(iFirstBlank + 1);
                        GivenName_textBox.Visible = true;
                        GivenName_label.Visible = true;
                        CompanyName_textBox.Visible = false;
                    }
                    else
                    {
                        Surname_textBox.Text = cEngName;
                        GivenName_label.Visible = false;
                    }
                    Chinese_textBox.Text = r.Field<string>("Chiname");
                    StuID_textBox.Text = string.Format("{0}", r.Field<int>("StudentID").ToString("000000"));
                    HKIDCard_textBox.Text = r.Field<string>("IdCard");
                    TelEmail_textBox.Text = r.Field<string>("TelEmail");
                    MemberOf_xtextBoxButton.MyText = r.Field<string>("GroupName");
                    cEngName = Surname_textBox.Text.Trim() + ", " + GivenName_textBox.Text.Trim();
                    //listView o=Courses_listView;

                }
                else
                {
                    // Handle case when no data is returned
                }
            }
        }
    }
}
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,008 questions
{count} votes

Accepted answer
  1. Jiachen Li-MSFT 32,296 Reputation points Microsoft Vendor
    2024-11-04T02:01:11.8+00:00

    Hi @BenTam ,

    CS0115 means that a method was marked as an override, but the compiler found no method to override.

    Ensure that Student_Form is inheriting from a class that implements IDisposable, typically Form if it's a WinForms application.

    Check your Student_Form.Designer.cs file for public partial class Student_Form : Form.

    Best Regards.

    Jiachen Li


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.