|
-
January 10th, 2006, 04:53 AM
#1
why time delay?
I am fetching data from sql server. I am using windows2000 professional
and the database is on the server system running server2003
there are lacks of records in the table, I am adding a particular field in the list box but it is taking too much time. Can we reduce the proccessing time by any mean
i am using the following lines
_________________________
cn.ConnectionString = "Provider=SQLOLEDB;Persist Security
Info=False;User ID=admin1234;Password=sql-server;Initial Catalog=db_cash; Data Source=sql-server"
cn.open
Dim ssql As String
ssql = "Select * from cb_payments_detail order by voucher_no"
Set rs = New ADODB.Recordset
rs.Open ssql, cn, adOpenDynamic, adLockPessimistic
rs.MoveFirst
rs.MoveFirst
Do Until j = 100000
List1.AddItem (rs!voucher_no)
rs.MoveNext
j = j + 1
Loop
rs.Close
__________________________________
regards
shiv
Last edited by shivkumar; January 10th, 2006 at 04:59 AM.
-
January 10th, 2006, 05:24 AM
#2
Re: why time delay?
Why would you retrieve all the fields if you are going to use just 1 field from the Query. I would optimize the query to rertrieve only one field. I would even make this field indexed in the database. That way I don't have to use Order BY in my Select Query. So your code would look like this
Code:
Dim ssql As String
ssql = "Select voucher_no from cb_payments_detail order by voucher_no"
Set rs = New ADODB.Recordset
'if i am only going to read the data, i wouldn't open it as Dynamic. I would open it as ForwardOnly
rs.Open ssql, cn, adOPenForwardOnly, adLockPessimistic
While Not rs.EOF
List1.AddItem (rs!voucher_no)
rs.MoveNext
Wend
rs.Close
And Shic, you need to use Code Tags while posting the code. It makes reading through the post easier and people can easily understand the problem/question.
Take a look http://www.codeguru.com/forum/misc.php?do=bbcode#code
Last edited by Shuja Ali; January 10th, 2006 at 05:28 AM.
-
January 10th, 2006, 05:37 AM
#3
Re: why time delay?
thanks a lot shuja
again "tusi great ho"
shiv
-
January 14th, 2006, 05:20 AM
#4
Re: why time delay?
Hi Shivkumar
As told please Use CodeTags its easy to be done. Look on the end of my Post In the signature I hve done an example how this works. This CodeTags are necessary because otherwise all spaces and Tabs are lost during Web Presentation. Then your code looks like a sausage difficult to read. So additional also Necessary to use Spaces in your code so its easy to see loops and if then elses
Your code looks then
Code:
Dim ssql As String ssql = "Select voucher_no from cb_payments_detail order by voucher_no"
Set rs = New ADODB.Recordset
'if i am only going to read the data, i wouldn't open it as Dynamic. I would open it as ForwardOnly
rs.Open ssql, cn, adOPenForwardOnly, adLockPessimistic
While Not rs.EOF
List1.AddItem (rs!voucher_no)
rs.MoveNext
Wend
rs.Close
Or an if statement would look like the following PseudoCode
Code:
if Forum =This and PeopleUsesTags then
Txt = "Programmers are Happy"
ProcessVoice Txt
else
ProzessVoice Explode
end if
Got me ?
 Jonny Poet
To be Alive is depending on the willingsness to help others and also to permit others to help you. So lets be alive. !
Using Code Tags makes the difference: Code is easier to read, so its easier to help. Do it like this: [CODE] Put Your Code here [/code]
If anyone felt he has got help, show it in rating the post.
Also dont forget to set a post which is fully answered to 'resolved'. For more details look to FAQ's about Forum Usage. BTW I'm using Framework 3.5 and you ?
My latest articles :
Creating a Dockable Panel-Controlmanager Using C#, Part 1 | Part 2 | Part 3 | Part 4 | Part 5 | Part 6 | Part 7
-
January 14th, 2006, 08:36 AM
#5
Re: why time delay?
TIP
I find that if you are populating a Grid or a Listbox, the performance is much, much faster by making the Grid or Listbox invisible prior to commencing the populating - then make it visible when you have finished.
Using your example -
Code:
Dim ssql As String
ssql = "Select voucher_no from cb_payments_detail order by voucher_no"
Set rs = New ADODB.Recordset
'if i am only going to read the data, i wouldn't open it as Dynamic. I would open it as ForwardOnly
rs.Open ssql, cn, adOPenForwardOnly, adLockPessimistic
List1.visible = False
While Not rs.EOF
List1.AddItem (rs!voucher_no)
rs.MoveNext
Wend
rs.Close
List1.Visible = True
Obviouly if you have 50 records coming into the Listbox, you may not notice a difference.
Try it with a good hearty list of items - 5000 to 10000 items
It is particularly noticable with MsFlexgrid !
-
January 15th, 2006, 08:37 AM
#6
Re: why time delay?
You would be better off not using the VB loop. These are inherently slow. Better would be to use a data bound control, which are much faster.
But if you are displaying that many options to the user, then I would say there is probably something you should be addressing in your GUI.
Mike
-
January 16th, 2006, 09:10 AM
#7
Re: why time delay?
Where it gets really interesting is having a Flexgrid showing a search result from a stock file, for example, and you want to highlight a column on the grid in a special colour - eg, a quantity to order column
So first you hide the grid (Grid.Visible = False)
Then you populate the grid with an sql statement using data binding
Then you have to run through the grid making the Order Qty column Yellow, for example
Then you make the Grid visible again (Grid.Visible = True)
The resulting Grid may be 1 item to thousands, depending on the user's search criteria, and the performance is enhaced incredibly by hiding the grid
You don't actually see the grid disappear, which is neat - it just seems to refresh based on the new search criteria
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|