读取数据库出错,方法或操作未实现 [英] Error reading the database, method or operation is not implemented
本文介绍了读取数据库出错,方法或操作未实现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以在修复了一个错误后,我得到 studentHelperClass.Form1.cmbBox 由于其保护级别而无法访问
我在启动我的程序时遇到了这个错误 Error reading the database, method or操作没有被我的错误标签实现
.
So after fixing an error where I was getting studentHelperClass.Form1.cmbBox is inaccessible due to its protection level
I got this error when I launched my prorgam Error reading the database, method or operation is not implemented
by my error label.
这是我的代码:
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;
}
}
那是表单的代码,下面是带有方法的类
That is the code for the form, the following is the class with the method
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()'由于其保护级别而无法访问
推荐答案
用这个替换你的 studentHC 类
replace your studentHC class with this
class studentHC : Form1
{
public studentHC()
{
InsertMethod();
}
public static 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"]);
}
}
}
}
然后替换
studentHelperClass.studentHC.insertMethod();
与
studentHelperClass.studentHC.InsertMethod();
这篇关于读取数据库出错,方法或操作未实现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文