Ver Mensaje Individual
  #3 (permalink)  
Antiguo 06/09/2006, 06:56
dixie
 
Fecha de Ingreso: noviembre-2002
Mensajes: 198
Antigüedad: 22 años, 3 meses
Puntos: 0
Mil gracias por contestar, lo he intentado usando un DataTable, pero me va muy lento y no me funciona, pongo el código por si veis algo raro:

Public Sub PruebasNacidos()
Dim linea As String
Dim anno As String
Dim region As String
Dim estado_civil As String
Dim edad As String
Dim orden As String
Dim dt As New DataTable


Dim srLector2 As StreamReader = New StreamReader(archivo)
linea = srLector2.ReadLine()

Do While Not (linea = Nothing)

LecturaDatosNacimiento(linea, anno, region, estado_civil, edad, orden, contador)
ActualizarTabla(anno, region, estado_civil, edad, orden, dt)

linea = srLector2.ReadLine()
Loop


ActualizarBaseDeDatos(dt, "Nacidos")


MsgBox("El proceso se ha realizado con éxito")


End Sub


Public Sub ActualizarBaseDeDatos(ByRef dt As DataTable, ByVal tableName As String)


Dim dts As New DataSet("Nacidos")
Dim nuevo_data As New getDataset

dts.Tables.Add(dt)
nuevo_data.dts2db2(dts, tableName)

End Sub

Public Sub ActualizarTabla(ByVal anno As String, ByVal region As String, ByVal estado_civil As String, ByVal edad As String, _
ByVal orden As String, ByRef dt As DataTable)

Dim str As String, valor


str = "Anno = '" & anno & "'"
str &= " AND Provincia = '" & region & "'"
str &= " AND Estado = '" & estado_civil & "'"
str &= " AND Edad = '" & edad & "'"

Dim rows() As DataRow = dt.Select(str)


If rows.Length() > 0 Then
Exit Sub
Dim r As DataRow

r = rows(0)

Select Case orden



Case " 1", "1 ", "01"

r.BeginEdit()
r("Orden1") = r(4) + 1
r("Total") = r(9) + 1
r.EndEdit()
dt.AcceptChanges()

Case " 2", "2 ", "02"

r.BeginEdit()
r("Orden2") = r(5) + 1
r("Total") = r(9) + 1
r.EndEdit()
dt.AcceptChanges()

Case " 3", "3 ", "03"

r.BeginEdit()
r("Orden3") = r(6) + 1
r("Total") = r(9) + 1
r.EndEdit()
dt.AcceptChanges()

Case " 4", "4 ", "04"

r.BeginEdit()
r("Orden4") = r(7) + 1
r("Total") = r(9) + 1
r.EndEdit()
dt.AcceptChanges()

Case Else
r.BeginEdit()
r("Orden5") = r(8) + 1
r("Total") = r(9) + 1
r.EndEdit()
dt.AcceptChanges()

End Select

'Añadimos
Else

Dim Nrows As DataRow
Nrows = dt.NewRow()
Nrows("Anno") = anno
Nrows("Provincia") = region
Nrows("Edad") = edad
Nrows("Estado") = estado_civil
Nrows("Orden1") = 0
Nrows("Orden2") = 0
Nrows("Orden3") = 0
Nrows("Orden4") = 0
Nrows("Orden5") = 0
Select Case orden

Case " 1", "1 ", "01"

Nrows("Orden1") = 1
Nrows("Total") = 1


Case " 2", "2 ", "02"

Nrows("Orden2") = 1
Nrows("Total") = 1

Case " 3", "3 ", "03"

Nrows("Orden3") = 1
Nrows("Total") = 1

Case " 4", "4 ", "04"

Nrows("Orden4") = 1
Nrows("Total") = 1

Case Else

Nrows("Orden5") = 1
Nrows("Total") = 1


End Select

dt.Rows.Add(Nrows)

End If

End Sub

ublic Function dts2db(ByVal dts As DataSet, ByVal tablename As String)
'Dim sSel As String = "INSERT INTO _TEF(anno,region,edad1,edad2,orden,valor) FROM _TEF"
Dim sSel As String = "SELECT * FROM " & tablename & " ORDER BY anno"
Dim dbDataAdapter As OleDbDataAdapter
connect()
' Crear un nuevo objeto del tipo DataAdapter
dbDataAdapter = New OleDbDataAdapter(sSel, conn)
' Crear los comandos de insertar, actualizar y eliminar
Dim cb As New OleDbCommandBuilder(dbDataAdapter)

dbDataAdapter.MissingSchemaAction = MissingSchemaAction.AddWithKey


Try
dbDataAdapter.Update(dts, tablename)
Catch ex As System.InvalidOperationException
MsgBox(ex.ToString)
Exit Function
Catch ex As System.Data.OleDb.OleDbException
MsgBox("Debe cerrar todas las aplicaciones Access")
MsgBox(ex.ToString)
Exit Function
End Try


dts.AcceptChanges()

End Function