我有这个错误studentHelperClass.Form1.cmbBox is inaccessible due to its protection level
对于我的这部分代码
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();
}
上面的代码用于 SELECT 查询以显示名为 person 的表的内容
我的表格中有这个
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;
}
}
我该如何解决这个错误?
我相信这是程序运行之前的最后一个错误
编辑:
这是我没有向您展示的代码的唯一部分..它与 cmbBox 无关:/
private void connection()
{
try
{
conn = new MySqlConnection(connstring); //make the connection object
conn.Open(); // try and open the connection
lblInfo.Text = " server version: " + conn.ServerVersion;
lblInfo.Text += "\n Connection is :" + conn.State.ToString();
}
catch (Exception err)
{
lblInfo.Text = " Error reading the database.";
lblInfo.Text += err.Message; ;
}
编辑编号 2:
private void InitializeComponent()
{
this.cmbBox = new System.Windows.Forms.ComboBox();
this.lblInfo = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// cmbBox
//
this.cmbBox.FormattingEnabled = true;
this.cmbBox.Location = new System.Drawing.Point(65, 9);
this.cmbBox.Name = "cmbBox";
this.cmbBox.Size = new System.Drawing.Size(121, 21);
this.cmbBox.TabIndex = 0;
我必须将其更改为公开?
好的,所以我使用属性窗口将 cmbBox 更改为受保护并删除了错误,但是现在我在数据库上的状态标签在我运行程序后给了我这个错误,知道为什么吗?
Error reading the database, method or operation is not implemented