
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会直接失败所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)