Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > .NET General

Vista - SetColumnError Takes a Long Time to Execute

Reply
 
Old 09-12-2008   #1 (permalink)
Charles Law


 
 

SetColumnError Takes a Long Time to Execute

I have a data table with ~1000 rows. I go through the rows one at a time,
checking the contents. If I find a cell with an error, e.g containing null,
I use SetColumnError on the data row to flag it.

Here's my code:

For Each dr As DataRow In MyDataTable.Rows
Dim MyValue As Integer

If dr("ID").Equals(DBNull.Value) Then
dr.SetColumnError("ID", "ID cannot be null") ' this take 1 to 2
seconds each time
Else
MyValue = CType(dr("ID"), Integer)
End If

...
Next

The problem is each call to SetColumnError takes about 1-2 seconds to
execute. This is an ice-age, and if I have 100 cells to flag it takes 100
seconds to go through the data.

Does anyone know why it takes so long for this method to execute?

I am using VS2008 SP1 on XP SP3. I am targeting V3.5 of the framework,
although I have V3.5 SP1 installed. This was a problem before I installed
SP1 though. The back-end is SQL Server 2005, but the data are disconnected,
so I can't see that being an issue.

TIA

Charles



My System SpecsSystem Spec
Old 09-13-2008   #2 (permalink)
Cor Ligthert[MVP]


 
 

Re: SetColumnError Takes a Long Time to Execute

Hi Charles,

Takes in Brittain a second the same time as at the continent?

:-)

\\\
Module Module1

Sub Main()
Dim a As New Stopwatch
a.Start()
Dim myDataTable As New DataTable
Dim ID As New DataColumn("ID")
myDataTable.Columns.Add(ID)

For i As Integer = 0 To 100
Dim dr = myDataTable.NewRow
dr("ID") = DBNull.Value
myDataTable.Rows.Add(dr)
Next

For Each dr As DataRow In myDataTable.Rows
Dim MyValue As Integer

If dr("ID").Equals(DBNull.Value) Then
dr.SetColumnError("ID", "ID cannot be null") ' this take
1 to 2 seconds each time
Else
MyValue = CType(dr("ID"), Integer)
End If
Next
Console.WriteLine(a.ElapsedMilliseconds / 1000)
Console.ReadLine()
End Sub

End Module
///

Cor

"Charles Law" <blank@xxxxxx> schreef in bericht
news:%23E3yLXQFJHA.6052@xxxxxx
Quote:

>I have a data table with ~1000 rows. I go through the rows one at a time,
>checking the contents. If I find a cell with an error, e.g containing null,
>I use SetColumnError on the data row to flag it.
>
> Here's my code:
>
> For Each dr As DataRow In MyDataTable.Rows
> Dim MyValue As Integer
>
> If dr("ID").Equals(DBNull.Value) Then
> dr.SetColumnError("ID", "ID cannot be null") ' this take 1 to 2
> seconds each time
> Else
> MyValue = CType(dr("ID"), Integer)
> End If
>
> ...
> Next
>
> The problem is each call to SetColumnError takes about 1-2 seconds to
> execute. This is an ice-age, and if I have 100 cells to flag it takes 100
> seconds to go through the data.
>
> Does anyone know why it takes so long for this method to execute?
>
> I am using VS2008 SP1 on XP SP3. I am targeting V3.5 of the framework,
> although I have V3.5 SP1 installed. This was a problem before I installed
> SP1 though. The back-end is SQL Server 2005, but the data are
> disconnected, so I can't see that being an issue.
>
> TIA
>
> Charles
>
My System SpecsSystem Spec
Old 09-13-2008   #3 (permalink)
Charles Law


 
 

Re: SetColumnError Takes a Long Time to Execute

Hi Cor

Good to hear from you. I tried your test, and it takes only a fraction of a
second, so there is obviously something about my data table that is causing
the problem.

I've just had another thought: I am using the data table as the data source
for a grid. I wonder if the fact that the grid is bound to the data table is
what is making it so slow. I'll have to look into that.

Cheers

Charles


"Cor Ligthert[MVP]" <notmyfirstname@xxxxxx> wrote in message
news:1F477A33-E6A9-4172-8DEA-29990C637A72@xxxxxx
Quote:

> Hi Charles,
>
> Takes in Brittain a second the same time as at the continent?
>
> :-)
>
> \\\
> Module Module1
>
> Sub Main()
> Dim a As New Stopwatch
> a.Start()
> Dim myDataTable As New DataTable
> Dim ID As New DataColumn("ID")
> myDataTable.Columns.Add(ID)
>
> For i As Integer = 0 To 100
> Dim dr = myDataTable.NewRow
> dr("ID") = DBNull.Value
> myDataTable.Rows.Add(dr)
> Next
>
> For Each dr As DataRow In myDataTable.Rows
> Dim MyValue As Integer
>
> If dr("ID").Equals(DBNull.Value) Then
> dr.SetColumnError("ID", "ID cannot be null") ' this take
> 1 to 2 seconds each time
> Else
> MyValue = CType(dr("ID"), Integer)
> End If
> Next
> Console.WriteLine(a.ElapsedMilliseconds / 1000)
> Console.ReadLine()
> End Sub
>
> End Module
> ///
>
> Cor
>
> "Charles Law" <blank@xxxxxx> schreef in bericht
> news:%23E3yLXQFJHA.6052@xxxxxx
Quote:

>>I have a data table with ~1000 rows. I go through the rows one at a time,
>>checking the contents. If I find a cell with an error, e.g containing
>>null, I use SetColumnError on the data row to flag it.
>>
>> Here's my code:
>>
>> For Each dr As DataRow In MyDataTable.Rows
>> Dim MyValue As Integer
>>
>> If dr("ID").Equals(DBNull.Value) Then
>> dr.SetColumnError("ID", "ID cannot be null") ' this take 1 to 2
>> seconds each time
>> Else
>> MyValue = CType(dr("ID"), Integer)
>> End If
>>
>> ...
>> Next
>>
>> The problem is each call to SetColumnError takes about 1-2 seconds to
>> execute. This is an ice-age, and if I have 100 cells to flag it takes 100
>> seconds to go through the data.
>>
>> Does anyone know why it takes so long for this method to execute?
>>
>> I am using VS2008 SP1 on XP SP3. I am targeting V3.5 of the framework,
>> although I have V3.5 SP1 installed. This was a problem before I installed
>> SP1 though. The back-end is SQL Server 2005, but the data are
>> disconnected, so I can't see that being an issue.
>>
>> TIA
>>
>> Charles
>>
>

My System SpecsSystem Spec
Old 09-23-2008   #4 (permalink)
Andrew Morton


 
 

Re: SetColumnError Takes a Long Time to Execute

Charles Law wrote:
Quote:

> Good to hear from you. I tried your test, and it takes only a
> fraction of a second, so there is obviously something about my data
> table that is causing the problem.
>
> I've just had another thought: I am using the data table as the data
> source for a grid. I wonder if the fact that the grid is bound to the
> data table is what is making it so slow. I'll have to look into that.
Maybe .SuspendLayout and .ResumeLayout on the grid would help?

Andrew


My System SpecsSystem Spec
Old 09-27-2008   #5 (permalink)
Charles Law


 
 

Re: SetColumnError Takes a Long Time to Execute

Hi Andrew

I did try that and it didn't improve things. It seems that it is the fact
that the data table is the data source for the grid. I set the data source
to Nothing and the SetColumnError takes a fraction of a second. So, I create
a copy of my data table to work on and then use the copy as the data source
at the end. I couldn't really think of a better way.

Cheers

Charles


"Andrew Morton" <akm@xxxxxx-press.co.uk.invalid> wrote in message
news:6jrpplF4pe4sU1@xxxxxx
Quote:

> Charles Law wrote:
Quote:

>> Good to hear from you. I tried your test, and it takes only a
>> fraction of a second, so there is obviously something about my data
>> table that is causing the problem.
>>
>> I've just had another thought: I am using the data table as the data
>> source for a grid. I wonder if the fact that the grid is bound to the
>> data table is what is making it so slow. I'll have to look into that.
>
> Maybe .SuspendLayout and .ResumeLayout on the grid would help?
>
> Andrew
>

My System SpecsSystem Spec
Old 09-27-2008   #6 (permalink)
Charles Law


 
 

Re: SetColumnError Takes a Long Time to Execute

Hi Steve

I tried the Nothing thing before, which did work, but decided to make a copy
instead to avoid the grid going blank during the process, but I appreciate
it will take longer when the data table has many rows.

I will try the BeginDataLoad though; that sounds like it could work.

Cheers

Charles


"Steve Gerrard" <mynamehere@xxxxxx> wrote in message
news:ZpmdnVQFfMjx7UPVnZ2dnUVZ_gudnZ2d@xxxxxx
Quote:

> Charles Law wrote:
Quote:

>> Hi Andrew
>>
>> I did try that and it didn't improve things. It seems that it is the
>> fact that the data table is the data source for the grid. I set the
>> data source to Nothing and the SetColumnError takes a fraction of a
>> second. So, I create a copy of my data table to work on and then use
>> the copy as the data source at the end. I couldn't really think of a
>> better way.
>> Cheers
>>
>> Charles
>>
>>
>
> Instead of SuspendLayout on the grid control, which really only effects
> the positioning on the form, you might try BeginLoadData and EndLoadData
> on the data table. This should turn off notifications during your
> modifications, which might cut down on all the grid updating until you are
> done.
>
> Rather than makiing a copy, I would also consider just setting the grid
> datasource to nothing, modifying the table, and then reassigning it as the
> datasource.
>
>

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Cmd takes long time to load Vista General
Windows takes a long time to log off Vista General
System takes a long time to boot Vista General
Vista takes a long time from start to long in on SBS2003 network...... Vista networking & sharing
setting flags takes a long long time Vista mail


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46