小编use*_*048的帖子

数据是空的.无法在空值上调用此方法或属性.(使用组合框)

嗨,我在表格中有空值,我将用它来填充组合框.我不知道该怎么做.当我运行以下代码时,我收到错误:

数据是空的.无法在空值上调用此方法或属性.

我需要帮助,我是mysql的新手

代码 :

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
    string constring = "datasource=localhost;port=3306;username=root;password=root";
    string Query = "SELECT * from database.check WHERE patientname IS NOT NULL";
    MySqlConnection conDataBase = new MySqlConnection(constring);
    MySqlCommand cmdDataBase = new MySqlCommand(Query, conDataBase);
    MySqlDataReader myReader;

    try
    {
        conDataBase.Open();
        myReader = cmdDataBase.ExecuteReader();

        while (myReader.Read())
        {
            string namethestore = myReader.GetString("namethestore");
            string checkername = myReader.GetString("checkername");
            this.textBox65.Text = namethestore;
            this.textBox66.Text = checkername;
        }
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message);
    }
}
Run Code Online (Sandbox Code Playgroud)

c# mysql box

4
推荐指数
1
解决办法
8980
查看次数

标签 统计

box ×1

c# ×1

mysql ×1