Re: Optimizing for speed

Tech-Archive recommends: Speed Up your PC by fixing your registry

From: Carlos Fernandez (CarlosFernandez_at_discussions.microsoft.com)
Date: 10/04/04


Date: Mon, 4 Oct 2004 07:13:03 -0700

Here's some some code (don't worry about variable names inconsistencies, I
just cut some parts of it so you don't have to see all the fields, etc).

myDataSet = New DataSet("ds_itinerarios")
tItin = New DataTable("itinerarios")
Dim cCodCliente As New DataColumn("CODE")
Dim cNomCliente As New DataColumn("NAME")
tItin.Columns.Add(cCodCliente)
tItin.Columns.Add(cNomCliente)
myDataSet.Tables.Add(tItin)
Dim MyCursor As SqlServerCe.SqlCeDataReader
MyCursor = dbc.createCursor("SELECT CODE,NAME FROM PRODUCTS")
While MyCursor.Read()
                Dim fila As DataRow
                fila = tItin.NewRow
                Dim codigo As String
                Dim nombre As String
                codigo = MyCursor("CODE")
                nombre = MyCursor("NAME")
                fila("CODIGO") = codigo
                fila("NOMBRE") = nombre
                tItin.Rows.Add(fila)
            End While ' End of cursor read
DataGrid1.RowHeadersVisible = False
DataGrid1.DataSource = tItin

"W.G. Ryan eMVP" wrote:

> What loop are you referencing? Are you using a DataReader and adding
> everything through it in the while dataReader.Read()? Otherwise if you have
> a DataTable, I'd just bind directly to it , or to a DataView and just
> manimpulate the RowFilter without changing the bindings.
>
> --
> W.G. Ryan, MVP
>
> www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
> "Carlos Fernandez" <CarlosFernandez@discussions.microsoft.com> wrote in
> message news:8E800305-CE97-4D20-8541-D98218498EAA@microsoft.com...
> > Ryan,
> >
> > Thanks for your quick reply. I'm going to read through your links
> carefully,
> > but in the mean time, this is the typical situation in the application:
> > Simple query (such as SELECT ID, CODE, STOCK FROM PRODUCTS) which returns
> > 1100 records or so. The grid (which has room for like 10-11 rows) displays
> ID
> > and CODE, while I use STOCK to display a msgbox if the user clicks on a
> > sold-out product.
> >
> > The query itself is fast, it's actually the loop that reads all the
> records
> > and takes the time. I'd like to inmediately display records and allow user
> > interaction. My idea is to fetch the minimum number of records, display
> them,
> > and load the rest as the user moves through the grid with the scrollbar
> but
> > maybe there's another way.
> >
> > Thanks.
> >
> > "W.G. Ryan eMVP" wrote:
> >
> > > Carlos:
> > >
> > > There's a lot of 'ifs' here that could be affecting things. The first
> thing
> > > I'd consider is how much data am I loading in the grid vs. what the user
> > > needs. If you're pulling out 1000 records but the user really only uses
> 10
> > > most of the time, then query size would definitely be something to look
> at.
> > > Another thing is how many trips to the db are you making? You have
> chioce 1
> > > of basically grabbing all the data and then storing the dataset as
> static
> > > property for instance which will front load processing time but save
> time
> > > over the long haul. In general, the as you need it approach is my
> leaning.
> > >
> > > As far as grids, you can't bind them to datareaders but if I just needed
> a
> > > value or two, I'd definitely look to using one where possible. Indexes
> are
> > > another thing. If you're really trying to squeeze out everythign that
> you
> > > can get, set the BeginLoadData method of any given datatable before you
> > > start loading the data
> > >
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemdatadatatableclasstopic.asp
> > > and then call EndLoadData
> > >
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemdatadatatableclasstopic.asp
> > > ..I'd also shut of the EnforceConstraints property of the dataset if you
> have
> > > them
> > >
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemDataDataSetClassTopic.asp -
> > > but don't leave them off of course, just set it back when you're done
> with
> > > the load. Lots less events will get fired if you do this - but I can't
> > > promise a huge performance increase because I don't know where the
> > > bottleneck is on your app. In some instances the diffferences are
> stunning,
> > > in others where this isn't the bottleneck the differences aren't worth
> > > mentioning.
> > >
> > > Those are the first thigns that come to mind, but if you could elaborate
> on
> > > what you mean by " put
> > > them in rows and display the grid " that may provide some insight into
> > > where the bottleneck is. At least the nice part of CE is that you don't
> > > have to worry about network congestion being the bottleneck ;-)
> > > "Carlos Fernandez" <CarlosFernandez@discussions.microsoft.com> wrote in
> > > message news:115783D8-1360-4CB3-91CE-A96A65EB9E05@microsoft.com...
> > > > Due to time constraint, my last project (first one in VB.NET for us, I
> > > might
> > > > add) was done 'quickly' rather that right, meaning that it is 'good
> > > enough'
> > > > for the client but not the kind of project one feels proud of after
> > > delivery.
> > > >
> > > > I happen to have some spare time on my hands which I plan to spend
> > > > optimizing the whole thing just to improve myself.
> > > >
> > > > One of the things I know we didn't do right, simple as it is, is the
> > > display
> > > > of SQL.CE based data on grids. We just execute a query, grab all
> records,
> > > put
> > > > them in rows and display the grid - slow as hell as you can easily
> guess.
> > > >
> > > > Given you have the data in one or several tables, what is the fastest
> way
> > > to
> > > > display it on a grid? Fastest as in 'fastest availabity to the user',
> so
> > > > retrieving records as needed by user interaction is fine. This is
> actually
> > > my
> > > > first idea.
> > > >
> > > > Also, suppose you need one of the fields from the query not for
> display
> > > but
> > > > for something else (i.e. you can't just feed the results to the
> datagrid,
> > > > even if it's possible to do so, which I'm not sure).
> > > >
> > > > All suggestions welcome, I have the time to try them all.
> > > >
> > >
> > >
> > >
>
>
>



Relevant Pages

  • Re: SQL access from Cobol Test
    ... Dim oWrite As System.IO.StreamWriter ... Dim workline As String ... 000380 01 NEW-GENERIC-REC. ... 000810 DISPLAY "INVALID READ FROM IMPORT TEXT FILE". ...
    (comp.lang.cobol)
  • SQL access from Cobol Test
    ... fetching on a SQL cursor in COBOL. ... Dim oWrite As System.IO.StreamWriter ... 000380 01 NEW-GENERIC-REC. ... 000810 DISPLAY "INVALID READ FROM IMPORT TEXT FILE". ...
    (comp.lang.cobol)
  • Re: Stay-on-top form?
    ... Global Const WM_SM_CXVSCROLL = 2 ... Dim DisplayHeight As Integer ... iRtn = WM_apiReleaseDC'release display contex ... Sub xg_MaximizeWindow ...
    (microsoft.public.access.formscoding)
  • Re: Stay-on-top form?
    ... Global Const WM_SM_CXVSCROLL = 2 ... Dim DisplayHeight As Integer ... iRtn = WM_apiReleaseDC'release display contex ... ' Maximize the active form window, ...
    (microsoft.public.access.formscoding)
  • Re: Need WMI script
    ... Dim strDomainName, strNodeText, strXmlBuilder ... ' Retrieve values and display. ... However, if you use the cscript host, ... you can use a command similar to below at a command prompt: ...
    (microsoft.public.windows.server.scripting)