空引用异常未处理

时间:2019-07-20 23:20:12

标签: c# mysql

当我尝试执行以下查询时,MySql.Data.dll中出现“ System.NullReferenceException”类型的未处理异常的错误

 private void Ingredients_Load(object sender, EventArgs e)
        {
            MySqlCommand cmd = new MySqlCommand();
            string query = "select count(*) from Inventory";

            cmd.CommandText = query;
            cmd.Connection = conn;
            flag = Convert.ToInt32(cmd.ExecuteScalar());
            conn.Close();

            for (int i = 1; i <= flag; i++)
            {
                comboBox1.Items.Add(i);
            }
        }

0 个答案:

没有答案