CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
不看会后悔的Windows XP之经验谈 简单快捷DIY实用家庭影院
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  .NET技术 >  C#

初学者:查询语句报错!请大家帮忙改错!

楼主herohero55(英雄)2005-10-30 14:44:36 在 .NET技术 / C# 提问

using   System;  
  using   System.Drawing;  
  using   System.Collections;  
  using   System.ComponentModel;  
  using   System.Windows.Forms;  
  using   System.Data;  
  using   System.Data.OleDb;  
  using   System.Data.SqlClient;   
     
  namespace   ConnectAccess  
  {  
  ///   <summary>  
  ///   Form1   的摘要说明。  
  ///   </summary>  
  public   class   Form1   :   System.Windows.Forms.Form  
  {  
  private   System.Windows.Forms.DataGrid   dataGrid1;  
  private   System.Windows.Forms.Button   button1;  
  private   System.Windows.Forms.Button   button2;  
  private   System.Windows.Forms.Button   button3;  
  private   System.Windows.Forms.Button   button4;  
  private   System.Windows.Forms.Button   button5;  
  private   System.Windows.Forms.TextBox   textBox1;  
  private   System.Windows.Forms.TextBox   textBox2;  
  private   System.Windows.Forms.Button   button6;  
  private   System.Windows.Forms.Button   button7;  
  private   System.Windows.Forms.Button   button8;  
  private   System.Windows.Forms.Button   button9;  
  ///   <summary>  
  ///   必需的设计器变量。  
  ///   </summary>  
  private   System.ComponentModel.Container   components   =   null;  
   
  private   void   button8_Click(object   sender,   System.EventArgs   e)  
  {  
  string   source="server=localhost;uid=sa;pwd=;database=student";  
  string   select="select   *   from   score";  
  SqlConnection   conn=new   SqlConnection(source);  
  conn.Open();  
  SqlCommand   cmd   =new   SqlCommand(select,conn);    
  SqlDataReader   reader=cmd.ExecuteReader();  
  this.dataGrid1.DataSource   =   reader;  
  }  
   
       }  
  }      
  我在datagrid中显示,但是报错,错误信息如下:  
  编译通过了,运行时出对话框  
   
  未处理的“System.Exception”类型的异常出现在   system.windows.forms.dll   中。  
  其他信息:   复杂的   DataBinding   接受   IList   或   IListSource   作为数据源  
   
   
  请大家帮忙! 问题点数:20、回复次数:8Top

1 楼jxufewbt(我的目标是5星)回复于 2005-10-30 14:51:12 得分 5

在this.dataGrid1.DataSource   =   reader;后面加上  
  this.dataGrid1.DataBind();  
  看看Top

2 楼herohero55(英雄)回复于 2005-10-30 15:01:24 得分 0

“System.Windows.Forms.DataGrid”并不包含对“DataBind”的定义  
   
  加上就出这个错误了。Top

3 楼zhy0101(莠)回复于 2005-10-30 15:09:14 得分 0

WinForm当中下列数据源有效:    
   
  DataTable    
  DataView    
  DataSet    
  DataViewManager    
  一维数组    
  任何实现   IListSource   接口的组件    
  任何实现   IList   接口的组件    
   
  不包括DataReader,使用DataSet  
  Top

4 楼herohero55(英雄)回复于 2005-10-30 15:36:28 得分 0

应该怎么写呢?  
  我是初学,不是很会Top

5 楼xlfeiyu()回复于 2005-10-30 16:09:58 得分 15

private   void   button8_Click(object   sender,   System.EventArgs   e)  
  {  
  string   source="server=localhost;uid=sa;pwd=;database=student";  
  string   select="select   *   from   score";  
  SqlConnection   conn=new   SqlConnection(source);  
  SqlDataAdapter   da   =   new   SqlDataAdapter(select,   conn);  
                                                          DataSet   ds   =   new   DataSet();  
                                                          da.Fill(ds);  
  this.dataGrid1.DataSource   =   ds.Table[0];  
  }  
   
       }  
  }      
  Top

6 楼herohero55(英雄)回复于 2005-10-30 16:58:20 得分 0

并不包含对Table的定义。  
   
   
  报此错Top

7 楼xlfeiyu()回复于 2005-10-30 17:11:10 得分 0

this.dataGrid1.DataSource   =   ds;Top

8 楼herohero55(英雄)回复于 2005-10-30 17:17:25 得分 0

OK,谢谢大有,结帖!Top

相关问题

  • 报错查询过于复杂,出现在update语句
  • insert 语句报错?
  • insert语句报错!
  • 我是DB2新手,请大家不佞赐教(一个查询语句报错)
  • 怎样在SQL查询语句中加入'和""号而不会报错!
  • 下面是一条SQL语句,Access数据库,日期查询,运行时出错报错
  • 输出的t-sql语句在查询分析器就能正常运行,为什么放在vb里就报错?!
  • 查询语句
  • 查询语句
  • 查询语句

关键词

  • datagrid
  • ds
  • source
  • button
  • forms
  • sqlconnection
  • datasource
  • conn
  • databind
  • private

得分解答快速导航

  • 帖主:herohero55
  • jxufewbt
  • xlfeiyu

相关链接

  • CSDN .NET频道
  • .NET类图书
  • C#类图书
  • .NET类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo