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()
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
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 !!!