Popolamento automatico database

martedì 01 giugno 2010 - 14.27

katana Profilo | Newbie

prima di tutto ciao a tutti

ho un problema abbastanza urgente da risolvere.

ho una tabella creata con Microsoft SQL Server con 3 campi;

tramite un ciclo do while creo diciamo i miei dati in vb dopodichè dovrei spararli dentro nella mia tabella. il problema è che questo do while ha un contatore e finchè non raggiunge il valore 15.000.000 non si ferma. in pratica devo generare 15.000.000 di record . la sub funziona solo che è troppo lenta in 14 ore ha riempito soltanto 800.000 record.. qualcuno sa aiutarmi a velocizzare questo processo?!

Private Sub GeneraRecord()

Dim dataAdapter As SqlDataAdapter
dataAdapter = New SqlDataAdapter("SELECT * FROM Posizioni ORDER BY IMEI", sqlConn)
Dim dataSet As DataSet
dataSet = New DataSet
Try
dataAdapter.Fill(dataSet)

Do While nr < 15000000

imei = imei + 1
If imei > 9999 Then
imei = 0
End If

lat = lat + 0.1
If lat > 90 Then
lat = 0
End If

lon = lon + 0.1
If lon > 80 Then
lon = 0
End If

times = times + 1
If times > 9999999999 Then
times = 0
End If

vel = vel + 0.1
If vel > 20 Then
vel = 0
End If

tipoe = tipoe + 1
If tipoe > 99 Then
tipoe = 0
End If

nr = nr + 1

Dim cb As New SqlCommandBuilder(dataAdapter)
Dim newTestRow As DataRow = dataSet.Tables(0).NewRow()

newTestRow(0) = imei
newTestRow(1) = lat
newTestRow(2) = lon
newTestRow(3) = times
newTestRow(4) = vel
newTestRow(5) = tipoe

dataSet.Tables(0).Rows.Add(newTestRow)


dataAdapter.Update(dataSet.Tables(0))

Loop


sqlConn.Close()
nr = 32768
Catch ex As Exception

MsgBox("errore")

End Try


End Sub

carloalberto Profilo | Junior Member

prova a spostare il tutto in una stored ... conto sia piu veloce
ciao

katana Profilo | Newbie

ok ma come faccio a tradurre questo dentro una stored?! so crearla una stored ma non riesco a tradurre tutta questa sub dentro una stored su sql server...

per esempio

imei=imei+1
if imei >9999 then
imei =0
end if

come diventerebbe dentro la stored?!

carloalberto Profilo | Junior Member

...
>imei=imei+1
>if imei >9999 then
>imei =0
>end if
...

declare @imei
set @imei=@imei+1
if @imei>9999 begin
set @imei=0
end

ciao
Partecipa anche tu! Registrati!
Hai bisogno di aiuto ?
Perchè non ti registri subito?

Dopo esserti registrato potrai chiedere
aiuto sul nostro Forum oppure aiutare gli altri

Consulta le Stanze disponibili.

Registrati ora !
Copyright © dotNetHell.it 2002-2024
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5