CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
山寨机中的战斗机! 程序优化工程师到底对IT界有没有贡献
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  .NET技术 >  ASP.NET

Datagrid数据连接问题

楼主nmgdahai(dahai)2005-12-08 13:48:35 在 .NET技术 / ASP.NET 提问

想将SQL的数据添加进datagrid中请问有几种方法,控件,对象。有原码最好,我功力太差了。 问题点数:20、回复次数:1Top

1 楼heriying(羽梦轻邻)回复于 2005-12-08 16:27:56 得分 20

可在查阅MSDN,,这里里面现在的@_@:  
  [C#]  
  <%@   Import   Namespace="System.Data"   %>  
  <%@   Import   Namespace="System.Data.SqlClient"   %>  
  <html>  
  <script   language="C#"   runat="server">  
        protected   void   Page_Load(Object   Src,   EventArgs   E)    
        {  
              //   Create   a   connection   to   the   "pubs"   SQL   database   located   on   the    
              //   local   computer.  
              SqlConnection   myConnection   =   new   SqlConnection("server=localhost;"   +  
                    "database=pubs;Trusted_Connection=Yes");  
              //   Connect   to   the   SQL   database   using   a   SQL   SELECT   query   to   get   all    
              //   the   data   from   the   "Authors"   table.  
              SqlDataAdapter   myCommand   =   new   SqlDataAdapter("SELECT   "   +  
                    "   *   FROM   Authors",   myConnection);  
              //   Create   and   fill   a   DataSet.  
              DataSet   ds   =   new   DataSet();  
              myCommand.Fill(ds);  
              //   Bind   MyDataGrid   to   the   DataSet.   MyDataGrid   is   the   ID   for   the    
              //   DataGrid   control   in   the   HTML   section.  
              DataView   source   =   new   DataView(ds.Tables[0]);  
              MyDataGrid.DataSource   =   source   ;  
              MyDataGrid.DataBind();  
        }  
  </script>  
   
  <body>  
        <%--   Display   the   DataGrid   information   in   the     body   of   the   page.   --%>  
        <h3><font   face="Verdana">Simple   SELECT   to   a   DataGrid   Control  
        </font></h3>  
        <%--   Display   the   data   in   a   DataGrid.   --%>  
        <ASP:DataGrid   id="MyDataGrid"   runat="server"  
              Width="700"  
              BackColor="#ccccff"    
              BorderColor="black"  
              ShowFooter="false"    
              CellPadding=3    
              CellSpacing="0"  
              Font-Name="Verdana"  
              Font-Size="8pt"  
              HeaderStyle-BackColor="#aaaadd"  
              EnableViewState="false"  
        />  
  </body>  
  </html>  
  Top

相关问题

  • DataGrid连接数据库问题
  • DataGrid与数据库的连接问题?
  • datagrid连接SQL server数据库数据表
  • datagrid控件用ADO连接数据库的问题
  • 用ado连接数据库的时候,用datagrid显示
  • vb数据库连接问题!!!datagrid控件.
  • 请问在vb.net中datagrid如何连接数据库? 多谢
  • 用ADO连接ACCESS,用DATAGRID显示数据,出现*****?
  • 数据库连接不上,adodc控件+access+datagrid
  • ADO数据库控件代码实现与DataGrid连接,急!

关键词

  • 数据
  • datagrid

得分解答快速导航

  • 帖主:nmgdahai
  • heriying

相关链接

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

广告也精彩

反馈

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