在Windows Orm的网格视图中显示数据 [英] showthe data in grid view for windows orm
本文介绍了在Windows Orm的网格视图中显示数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
为此,我编写了代码
如下
Dim conn As 新 SqlClient.SqlConnection(" )
conn.Open()
Dim cmd As 新建 SqlCommand(" ,conn)
cmd.CommandType = CommandType.StoredProcedure
Dim dr As SqlDataReader = cmd.ExecuteReader()
Dim ds As 新建 DataSet()
Dim dt As New DataTable(" )
ds.Tables.Add(dt)
ds.Load(dr,LoadOption.PreserveChanges,ds.Tables( 0 ))
dgvClass.DataSource = ds.Tables( 0 )
Dr.Close()
conn.Close()
其中tgvClass是gridView名称
这段代码没有显示错误,也不会在网格视图中显示数据
请从这个
帮助我
谢谢和问候
subiya
解决方案
您需要调用gridview的databind方法来显示数据.
希望本文将对此进行介绍.解释一些有关Windows窗体和数据绑定的有趣观点:
C#2.0中的BindingSource和BindingNavigator [Dim conn As New SqlClient.SqlConnection("Server=localhost;DataBase=cbse;Integrated Security=SSPI") conn.Open() Dim cmd As New SqlCommand("spClassSelect", conn) cmd.CommandType = CommandType.StoredProcedure Dim dr As SqlDataReader = cmd.ExecuteReader() Dim ds As New DataSet() Dim dt As New DataTable("tblClass") ds.Tables.Add(dt) ds.Load(dr, LoadOption.PreserveChanges, ds.Tables(0)) dgvClass.DataSource = ds.Tables(0) dr.Close() conn.Close()
where tgvClass is the gridView name
this code shows no error bt not showing data in the grid view as well
please help me out from this
thanks and regard
subiya解决方案You need to call the databind method of the gridview for it to show the data.
Hopefully this article will explain a few interesting points about Windows Forms and databinding:
BindingSource and BindingNavigator in C# 2.0[^].
It''s usually a good idea to use BindingSource when you are working with Windows Forms :)
Christians solution works very well when you are working with ASP.NET ...
Best regards
Espen Harlinn
这篇关于在Windows Orm的网格视图中显示数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文