读取数据库出错,方法或操作未实现

编程入门 行业动态 更新时间:2024-10-25 23:31:27
本文介绍了读取数据库出错,方法或操作未实现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

所以在修复了一个错误后,我得到 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();

更多推荐

读取数据库出错,方法或操作未实现

本文发布于:2023-11-14 19:10:14,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1588289.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:操作   数据库   方法

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!