所以在修复了一个错误后,我得到了 studentHelperClass.Form1.cmbBox is unaccessible due to its protection level
当我启动我的 prorgam Error reading the database, method or我的错误标签未实现操作
。
这是我的代码:
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();
}
}
任何输入将不胜感激
编辑:
好的,所以我摆脱了
internal static void insertMethod()
{
throw new NotImplementedException();
}
我变了
public studentHC()
{
InsertMethod();
}
private void InsertMethod()
到
public studentHC()
{
insertMethod();
}
private void insertMethod()
现在它说 studentHelperClass.studentHC.insertMethod()' 由于其保护级别而无法访问
最佳答案
您的 insertMethod
抛出此异常。看看它的代码,它抛出一个 NotImplementedException
...
如何解决这个问题,我不能告诉你,因为我真的不确定你这里的类结构......
一种可能是简单地将代码从 InsertMethod
移动到 insertMethod
关于c# - 读取数据库出错,方法或操作未实现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18720060/