R
RvGrah
In Vb.Net I used to use this code to put a few thousand numbers into an
array and then use the AddRange method to add them all at once to an
auto-complete combobox. It was hundreds of times faster than adding the
items directly to the combobox as I iterated through the SqlDataReader.
Since you can't redim Preserve in C# and you can't know the
datareader's count until after you close it, how would I do this in C#?
Dim jnumber(499) as Integer
Dim x as Integer
Dim drJobs As SqlDataReader = cmdAllNums.ExecuteReader
If drJobs.HasRows Then
Do While drJobs.Read
jnumber(x) = drJobs("JobName")
x += 1
If x Mod 500 = 0 Then ReDim Preserve jnumber(x + 499)
Loop
End If
drJobs.Close()
cbJobs.Items.AddRange(jnumber)
array and then use the AddRange method to add them all at once to an
auto-complete combobox. It was hundreds of times faster than adding the
items directly to the combobox as I iterated through the SqlDataReader.
Since you can't redim Preserve in C# and you can't know the
datareader's count until after you close it, how would I do this in C#?
Dim jnumber(499) as Integer
Dim x as Integer
Dim drJobs As SqlDataReader = cmdAllNums.ExecuteReader
If drJobs.HasRows Then
Do While drJobs.Read
jnumber(x) = drJobs("JobName")
x += 1
If x Mod 500 = 0 Then ReDim Preserve jnumber(x + 499)
Loop
End If
drJobs.Close()
cbJobs.Items.AddRange(jnumber)