0

そのため、エラーを修正した後、エラーラベルstudentHelperClass.Form1.cmbBox is inaccessible due to its protection levelでプログラムを起動したときにこのエラーが発生しError reading the database, method or operation is not implementedました。

これは私のコードです:

public partial class Form1 : Form
    {
        MySqlConnection conn; // connection object;
        string connstring = "server=localhost;user Id=root;database=collegesystem;Convert Zero Datetime=True ";

        public Form1()
        {
            InitializeComponent();
            connection();
            selectStudent();
        }


        private void selectStudent()
        {
            try
            {
                studentHelperClass.studentHC.insertMethod();
            }

            catch (Exception err)
            {
                lblInfo.Text = " Error reading the database.";
                lblInfo.Text += err.Message;
            }
        }

それはフォームのコードです。以下はメソッドを持つクラスです

class studentHC : Form1
    {
        public studentHC()
        {
            InsertMethod();
        }

        private void InsertMethod()
        {
            MySqlConnection conn; // connection object;
            string connstring = "server=localhost;user Id=root;database=collegesystem;Convert Zero Datetime=True ";
            conn = new MySqlConnection(connstring);
            conn.Open();
            using (var command = new MySqlCommand("SELECT * FROM person", conn))
            {
                using (var myReader = command.ExecuteReader())
                {
                    cmbBox.Items.Add(myReader["personID"]);
                }
            }
        }

        internal static void insertMethod()
        {
            throw new NotImplementedException();
        }
    }

どんな入力でも大歓迎です

編集:

OK、だから私は取り除きました

internal static void insertMethod()
{
    throw new NotImplementedException();
}

そして私は変わった

public studentHC()
{
    InsertMethod();
}

private void InsertMethod()

public studentHC()
{
    insertMethod();
}

private void insertMethod()

そして今それは言いますstudentHelperClass.studentHC.insertMethod()' is inaccessible due to its protection level

4

3 に答える 3

2

あなたinsertMethodはこの例外をスローします。そのコードを見てください、それは投げていNotImplementedExceptionます...

ここであなたのクラス構造について本当にわからないので、これを修正する方法はわかりません...

1 つの可能性は、単純にコードを からInsertMethodに移動することです。insertMethod

于 2013-09-10T13:22:32.723 に答える