c# – 将DataGridView绑定到DataSet会直接失败

c# – 将DataGridView绑定到DataSet会直接失败,第1张

概述由此代码绑定的DataGridView不会按预期显示信息: dataGridView1.DataSource = ds; 这是ds的代码: public DataSet ConnectandReadList() { DataSet ds = new DataSet(); string connection_string="Data 由此代码绑定的DataGrIDVIEw不会按预期显示信息:

dataGrIDVIEw1.DataSource = ds;

这是ds的代码:

public DataSet ConnectandReadList()        {            DataSet ds = new DataSet();            string connection_string="Data Source=hermes;database=qcvalues; Integrated Security=sspI;";                        using (var myConnection = new sqlConnection(connection_string))            {                myConnection.open();                var command = new sqlCommand(Initializequery(),myConnection);                var adapter = new sqlDataAdapter(command);                adapter.Fill(ds);            }            return ds;        }
解决方法 尝试绑定到数据集内的表:dataGrIDVIEw1.DataSource = ds.tables [0];

从DataGridView.DataSource属性的文档中,您还可以绑定到DataSet并使用DataMember属性:

When binding to a data source that contains multiple Lists or tables,you must set the DataMember property to a string that specifIEs the List or table to bind to.

我认为在这种情况下,表名称将是“表”,因为您没有明确地命名它.

总结

以上是内存溢出为你收集整理的c# – 将DataGridView绑定到DataSet会直接失败全部内容,希望文章能够帮你解决c# – 将DataGridView绑定到DataSet会直接失败所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/langs/1216308.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-06-05
下一篇2022-06-05

发表评论

登录后才能评论

评论列表(0条)

    保存