现在我在一个名为 HelperClass 的类中有这段代码:
class HelperClass : CollegeSystem.GUI
{
public void selectStudent()
{
MySqlConnection conn; // connection object;
string connstring = "server=localhost;user Id=root;database=collegesystem;Convert Zero Datetime=True ";
try
{
conn = new MySqlConnection(connstring);
conn.Open();
MySqlCommand myCommand = new MySqlCommand("SELECT * FROM person", conn);
MySqlDataReader myReader;
myReader = myCommand.ExecuteReader();
cmbTable.Items.Clear();
while (myReader.Read())
{
cmbTable.Items.Add(myReader["personID"] + " | " + myReader["firstName"] + " | " + myReader["lastName"] + " | " + myReader["address"] + " | " + myReader["phoneNumber"] + " | " + myReader["postCode"] + " | " + myReader["dateOfBirth"]);
}
}
catch (Exception err)
{//handle the error with a message
lblInfo.Text = " Error reading the database.";
lblInfo.Text += err.Message; ;
}
finally
{
}
我想从我的表格中调用它,但它不起作用:
private void fillcomboBox()
{
selectStudent();
}
当前上下文中不存在名称“selectStudent”
我把它放在表格的顶部:
public partial class GUI : Form, College_System.HelperClass
我错过了什么吗?
PS。为什么cmbTable
和lblInfo
由于它的保护级别而无法访问?谢谢你。