Click here to Skip to main content
15,892,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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

VB
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

VB
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 !!!
Posted
Comments
hypermellow 1-Sep-15 6:11am    
Hi, is there a reason why you are adding the rows to the DataGridView manually?
What timings do you get if you DataBind() the DataTable to the DataGridView?
[no name] 1-Sep-15 6:39am    
//try here
gvDetails.DataSource = ds
gvDetails.DataBind()

1 solution

DataSource and DataBind should help you to automatically bind the records. Don't use these loops and all.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900