标题:GridView无法显示
只看楼主
yxhrgyj
Rank: 1
等 级:新手上路
帖 子:22
专家分:0
注 册:2012-2-5
结帖率:100%
已结贴  问题点数:4 回复次数:4 
GridView无法显示
protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            SqlDataReader MyReader;
            SqlConnection MyConnection = new SqlConnection();
            MyConnection.ConnectionString = (@"Data Source=RGYJ-AVTYN682XD;Initial Catalog=库;User ID=sa;Password=sa123456789");
            SqlCommand MyCommand = new SqlCommand();
             = "SELECT * FROM 销售";
             = CommandType.Text;
            MyCommand.Connection = MyConnection;
            MyCommand.Connection.Open();
            //Response.Write("连接成功");
            MyReader = MyCommand.ExecuteReader(CommandBehavior.CloseConnection);
            GridView1.DataSource = MyReader;
            GridView1.DataBind();
        }
    }


运行以后为什么 GridView控件部分显示是空白 求解释
搜索更多相关主题的帖子: void 销售 
2012-03-23 16:52
guming
Rank: 4
等 级:业余侠客
威 望:5
帖 子:329
专家分:277
注 册:2006-11-9
得分:1 
把代码改成以下试试:
 ...
 MyReader = MyCommand.ExecuteReader();
 GridView1.DataSource = MyReader;
 GridView1.DataBind();

 MyReader.Close();
 MyConnection.Close()

不想停留。。。
2012-03-26 05:23
yhmm
Rank: 2
等 级:论坛游民
帖 子:22
专家分:72
注 册:2012-2-27
得分:1 
过滤转化了


                      捷建软件开发互助平台
2012-03-27 13:10
hhy420459674
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:203
专家分:179
注 册:2010-4-9
得分:1 
我用你的代码测试过,如果你的连接是成功了的,并且数据库中有数据,那么是可以显示出结果的。
测试连接是否成功的代码:
if (!Page.IsPostBack)
        {
            SqlDataReader MyReader;
            SqlConnection MyConnection = new SqlConnection();
            MyConnection.ConnectionString = (@"Data Source=RGYJ-AVTYN682XD;Initial Catalog=库;User ID=sa;Password=sa123456789");
            SqlCommand MyCommand = new SqlCommand();
             = "SELECT * FROM 销售";
             = CommandType.Text;
            MyCommand.Connection = MyConnection;
            MyCommand.Connection.Open();
            if (MyConnection.State == ConnectionState.Open)
                Response.Write("连接成功");
            else
               Response.Write("连接失败");            
            MyReader = MyCommand.ExecuteReader(CommandBehavior.CloseConnection);
            GridView1.DataSource = MyReader;
            GridView1.DataBind();
            MyReader.Close();
            MyReader.Dispose();
        }


看看链接数据库是不是成功的
2012-03-27 16:28
tongxin720
Rank: 2
等 级:论坛游民
帖 子:3
专家分:11
注 册:2012-3-12
得分:1 
呵呵
2012-03-27 20:14



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-364112-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.012563 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved