vs 2010中datagridview中的sqlDataReader值 [英] sqlDataReader value in a datagridview in vs 2010

查看:92
本文介绍了vs 2010中datagridview中的sqlDataReader值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨 我想在vs 2010中的datagridview中显示sqlDataReader值
我使用此代码:

SqlDataReader dr;
dr = com.ExecuteReader();
Datagrid1.DataSource = dr;


但它不起作用,在vs 2010中没有要绑定的databind方法

解决方案

这不是使用SQLDataReader的方法:

           SqlDataReader dr;
dr = com.ExecuteReader();
Datagrid1.DataSource = dr;


SQLDatareader是连接模式的事物,因此您不能不关闭它就返回它的实例.

看这里并阅读使用方法:
使用DataReader(ADO.NET)检索数据 [ ^ ]
SqlDataReader类 [


hi i want to show sqlDataReader value in a datagridview in vs 2010
i used this code:

SqlDataReader dr;
dr = com.ExecuteReader();
Datagrid1.DataSource = dr;


but it doesn''t work and there is no databind method to bind in vs 2010
so how can i show it in datagridview?

This is not the way to use SQLDataReader:

           SqlDataReader dr;
dr = com.ExecuteReader();
Datagrid1.DataSource = dr;


SQLDatareader is connected mode thing and thus you cannot just return it''s instance without closing it.

Look here and read on how to use it:
Retrieving Data Using a DataReader (ADO.NET)[^]
SqlDataReader Class[^]


About: there is no databind method to bind in vs 2010
In Winforms, you don''t need a Databind method. All you need is to define the datasource.

Try!


try this:

SqlConnection connection = new SqlConnection("Your connection string");
      
            connection.Open();
            SqlDataAdapter dt = new SqlDataAdapter("Your select query", connection);

            DataSet ds = new DataSet();

            dt.Fill(ds);

            GridView1.DataSource = ds;
            GridView1.DataBind();
            
            connection.Close();


这篇关于vs 2010中datagridview中的sqlDataReader值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆