C# 不可调用成员 'ProdhimiQumështit.DataTabel' 不能像方法一样使用

问题描述

最近,我尝试将其他表单中的信息填充到此表单中的组合框自动化。但它说无法使用此方法。 我该怎么做?

 private void FillLopId()
        {
            Con.open();
            sqlCommand cmd = new sqlCommand("select LopId from LopTabel",Con);
            sqlDataReader Rdr;
            Rdr = cmd.ExecuteReader();
            DataTable dt = DataTabel();
            dt.Columns.Add("LopId",typeof(int));
            dt.Load(Rdr);
            LopaIdCb.ValueMember = "LopId";
            LopaIdCb.DataSource = dt;
            Con.Close();
        }

解决方法

您应该将行 DataTable dt = DataTabel(); 更改为 DataTable dt = new DataTabel();

您正在尝试创建类的新实例。为此,您需要使用 new 运算符。 DataTable 是一个类,因此您不能像调用方法一样调用它。

,

我认为这是不正确的 数据表 dt = 数据表();

没有名为 DataTabel 的类, 相反应该是 DataTable dt = new DataTable();