微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

我们如何在 Windows 窗体 C# 中将数据库中的数据显示到 DataGridViewComboBoxColumn 中?

如何解决我们如何在 Windows 窗体 C# 中将数据库中的数据显示到 DataGridViewComboBoxColumn 中?

我们如何在 Windows 窗体 C# 中将数据库中的数据显示到 DataGridViewComboBoxColumn 中?

我的数据库表票是这样的:

enter image description here

我想将它显示到我的 dataGridView 中,它有两个名为 cbxSeverity 和 cbxStatus 的 DataGridViewComboBoxColumn:

enter image description here

我尝试了教程中的以下代码,但它不适用于 ComboBoxColumn:

        con.open();
        cmd = con.CreateCommand();
        cmd.CommandType = CommandType.Text;
        cmd.CommandText = "SELECT * FROM Ticket";
        cmd.ExecuteNonQuery();
        dt = new DataTable();
        da = new sqlDataAdapter(cmd);
        da.Fill(dt);
        dataGridView.DataSource = dt;
        con.Close();

我是新手,我看的教程只使用了TextBoxColumn,请指教,谢谢。

解决方法

感谢您的评论,我没有添加 DataPropertyName。添加它修复了输出

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。