如何在VB.NET 2010中将数据从DataSet传输到DataGridView? [英] How to transfer data from a DataSet to DataGridView in VB.NET 2010 ?

查看:95
本文介绍了如何在VB.NET 2010中将数据从DataSet传输到DataGridView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!



我有一个奇怪的问题。



我在工作VB.NET 2010与SQL Server 2008 DB的项目。



我正从DataSet中的数据库中检索数据,然后将Data从DataSet传输到DataGridView。 br />


这个过程由两部分组成。



第一部分: -

从数据库存储过程中检索数据并存储在数据集中。

这个代码如下:



Hello to All !

I have a strange problem.

I am working in a project of VB.NET 2010 with SQL Server 2008 DB.

I am retrieving data from database in a DataSet and then transfer this the Data from DataSet to a DataGridView.

This process is consisted of 2 parts.

First Part:-
Retrieving Data from Database stored procedure and store in a DataSet.
The code for this is given below

SQL_Connection.Open()
Dim MyDataSet As New DataSet
Dim MyQuery As String = "Execute MyStoredProcedureName"
Dim MyDataAdapter As New SqlDataAdapter(MyQuery, SQL_Connection)
MyDataAdapter.TableMappings.Add(0, "tbl_tablename")
MyDataSet = New System.Data.DataSet
MyDataAdapter.Fill(MyDataSet)
MyDataSet.Tables(0).TableName = "tbl_tablename"
SQL_Connection.Close()







第二部分:

在这部分中,我将数据从DataSet传输到DataGridView

这个代码如下:






Second Part:
In this part i transfer the data from DataSet to a DataGridView
The code for this is given below

With grd_MyDataGridView
Dim RowNo As Long = 0
.RowCount = 0
While RowNo <= MyDataSet.Tables(0).Rows.Count - 1
.Rows.Add(1)
.Rows(RowNo).Cells(0).Value = MyDataSet.Tables(0).Rows(RowNo).Item(0)
.Rows(RowNo).Cells(1).Value = MyDataSet.Tables(0).Rows(RowNo).Item(1)
.Rows(RowNo).Cells(2).Value = MyDataSet.Tables(0).Rows(RowNo).Item(2)
.Rows(RowNo).Cells(3).Value = MyDataSet.Tables(0).Rows(RowNo).Item(3)
.Rows(RowNo).Cells(4).Value = MyDataSet.Tables(0).Rows(RowNo).Item(4)
.Rows(RowNo).Cells(5).Value = MyDataSet.Tables(0).Rows(RowNo).Item(5)
RowNo = RowNo + 1
End While
End With





现在让我解释一下问题是???

第一部分执行得非常快(不到一分钟)...

但非常奇怪的是在第二部分,我只是转移了从DataSet到DataGridView的数据需要超过4秒,这意味着比第一部分慢近5倍。



我真的很震惊,因为根据常识第一部分必须慢于第二部分部分是因为在这部分数据是在网络中传播的。它从服务器开始旅行,并通过sql语句进入客户端系统。但在第二部分中,数据位于系统RAM中并在同一RAM内传输位置。这意味着它正在从一个内存位置转移到同一个RAM中的另一个内存位置........



这是一个非常神秘的高级。



为什么第二部分比第一部分慢得多。

相反它应该比第一部分更快。



任何人都可以找出我犯错的地方????????



提前致谢! !



Now let me explain what the problem is ???
The firs part is executing very quickly (less than a minute) ...
But very strangely in the second part where i m just shifting the data from the DataSet to the DataGridView it takes more than four seconds thats mean almost 5 time slower than the first part.

I m really very Shocked because according to common sense the first part must be slower than the second part because in this part data is traveling in the network. it starts travel from server and comes in the client system through sql statement. But in the second part the data is in the system RAM and transfer the location within the same RAM. It means that it is shifting from one memory location to the other memory location within the same RAM ........

This is a quite Mysterious senior.

Why the second part is much slower then the first part.
Instead it should be faster even then the first part.

Can anyone find out where i m making mistake ????????

Thanks in advance !!!

推荐答案

DataSource DataBind 应该可以帮到你自动绑定记录。不要使用这些循环和所有。
DataSource and DataBind should help you to automatically bind the records. Don't use these loops and all.


这篇关于如何在VB.NET 2010中将数据从DataSet传输到DataGridView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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