在此表中插入了数据,但数据网格视图显示为空值。

问题描述 投票:-2回答:1

c# winforms visual-studio-2019 qsqlquery
1个回答
0
投票

根据你的标题,你想把文本框的值插入到datatable中,然后使用

datagridview来显示它。

如果你想这样做,请参考下面的代码示例。

public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        DataTable table = new DataTable();
        private void button1_Click(object sender, EventArgs e)
        {
            table.Rows.Add(txtName.Text, txtAge.Text, txtID.Text, txtScore.Text);
            dataGridView1.DataSource = table;
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            table.Columns.Add("Name", typeof(string));
            table.Columns.Add("Age", typeof(string));
            table.Columns.Add("Id", typeof(string));
            table.Columns.Add("Score", typeof(string));
        }
    }

结果。enter image description here

如果上面的代码不能解决你的问题,你可以提供具体的异常和一段完成的代码。

© www.soinside.com 2019 - 2024. All rights reserved.