简体   繁体   English

由于其保护级别,DataTable dt 无法访问

[英]DataTable dt is inaccessible due its protection level

I want to add a row from my DateTimePicker, TextBoxes and ComboBox (which are on form2) to DGV (form1), and now I get the message:我想从我的 DateTimePicker、TextBoxes 和 ComboBox(在 form2 上)添加一行到 DGV(form1),现在我收到消息:

'Overzicht.File.dt' is inaccessible due to its protection level. 'Overzicht.File.dt' 由于其保护级别而无法访问。

How do I solve this?我该如何解决这个问题?

This is form1这是form1

using System;
using System.Data;
using System.Windows.Forms;

namespace Javell_Administratie_Software
{
    public partial class Overzicht : Form
    {
        public Overzicht()
        {
            InitializeComponent();
            Overzicht1.AutoGenerateColumns = false;
        }

        public DataTable table
        {
            set
            {
                File myFile = new File();
                table = myFile.dt;
            }

//above at myFile.dt its giving me the error

            get
            {
                return table;
            }
        }        

        public class File
        {
            DataTable dt = new DataTable();
            DataSet ds = new DataSet();

            public void RekeningenOverzicht()
            {
                Overzicht oz = new Overzicht();
                foreach (DataGridViewColumn col in oz.Overzicht1.Columns)
                {
                    dt.Columns.Add(col.Name);
                    col.DataPropertyName = col.Name;
                }
                ds.Tables.Add(dt);
                oz.Overzicht1.DataSource = dt;
            }
        }
    
        public void AddDataTableRow()
        {
            Toevoegen tv = new Toevoegen();
            Object row = new Object[]
            { 
              tv.dateTimePicker1.Value, tv.textBox1.Text,             
              tv.textBox2.Text, tv.textBox3.Text, tv.textBox4.Text,
              tv.textBox5.Text, tv.comboBox1.Text
            };
            table.Rows.Add(row);
            Overzicht1.DataSource = table;
            Overzicht1.Update();
            tv.Close();
        }

        public void Toevoegen1_Click(object sender, EventArgs e)
        {
            Toevoegen tv = new Toevoegen();
            tv.Show();
        }
    }
}

This is form2这是form2

using System;
using System.Windows.Forms;

namespace Javell_Administratie_Software
{

    public partial class Toevoegen : Form
    {

        public Toevoegen()
        {
            InitializeComponent();
        }       

        public void Toevoegen2_Click(object sender, EventArgs e)
        {
            Overzicht oz = new Overzicht();
            oz.AddDataTableRow();
        }
    }
}

If you want DataTable dt from your class File to be visible you need to set them as such如果您希望类 File 中的 DataTable dt 可见,则需要将它们设置为

Public DataTable dt = new DataTable();
Public DataSet ds = new DataSet();

If they arent public they cant be seen outside the class如果他们不公开,他们就不能在课堂外被看到

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM