Public Sub Familias()
Dim oGenArch As New GenerarArch(oApplicationContext)
Dim dsMultU As DataSet, drMultU As DataRow, vlComando As String, vlCadena As String
CrearDBF("C:\DPT\AUD\", "FAMILIA", "[Codigo] TEXT (2), [Nombre] TEXT (25)")
Dim oConDBF As New ADODB.ConnectionClass
Dim oRstDBF As New ADODB.RecordsetClass
oConDBF.Open("DRIVER={Microsoft dBASE Driver (*.dbf)};DBQ=C:\DPT\AUD\")
oRstDBF.Open("SELECT * FROM [FAMILIA];", oConDBF, ADODB.CursorTypeEnum.adOpenDynamic, ADODB.LockTypeEnum.adLockOptimistic, ADODB.CommandTypeEnum.adCmdText)
vlComando = "SELECT * FROM CatalogoFamilias"
dsMultU = DatosATrans(vlComando, "CatalogoFamilias")
For Each drMultU In dsMultU.Tables(0).Rows
oRstDBF.AddNew()
oRstDBF.Fields("Codigo").Value = drMultU!CodFamilia
vlCadena = drMultU!Descripcion
If vlCadena.Length > 25 Then
oRstDBF.Fields("Nombre").Value = vlCadena.Substring(0, 25)
Else
oRstDBF.Fields("Nombre").Value = drMultU!Descripcion
End If
oRstDBF.Update()
Next
dsMultU = Nothing
oRstDBF.Close()
oConDBF.Close()
End Sub
Public Sub CrearDBF(ByVal Base As String, ByVal Nombre As String, ByVal Campos As String)
Dim pconBase As Odbc.OdbcConnection
Dim pcmdTB As Odbc.OdbcCommand
pconBase = New Odbc.OdbcConnection
pcmdTB = New Odbc.OdbcCommand
pconBase.ConnectionString = "DRIVER={Microsoft dBASE Driver (*.dbf)};DBQ=" & Base
pconBase.Open()
pcmdTB.CommandText = "CREATE TABLE [" & Nombre & "] (" & Campos & ");"
pcmdTB.Connection = pconBase
pcmdTB.ExecuteNonQuery()
pconBase.Close()
End Sub
Public Function DatosATrans(ByVal strComandSQL As String, ByVal strTabla As String) As DataSet
Dim sccnnConnection As New SqlConnection(oApplicationContext.ApplicationConfiguration.DataStorageConfiguration. _
GetConnectionString)
Dim sccmdSelectAll As SqlCommand
Dim scdaMovCont As SqlDataAdapter
Dim dsMovCont As DataSet
sccmdSelectAll = New SqlCommand
scdaMovCont = New SqlDataAdapter
dsMovCont = New DataSet
With sccmdSelectAll
.Connection = sccnnConnection
.CommandText = "[DatosATrans]"
.CommandType = System.Data.CommandType.StoredProcedure
.Parameters.Add(New System.Data.SqlClient.SqlParameter("@ComandSQL", System.Data.SqlDbType.Text))
End With
scdaMovCont.SelectCommand = sccmdSelectAll
Try
sccnnConnection.Open()
scdaMovCont.SelectCommand.Parameters("@ComandSQL").Value = strComandSQL
'Fill DataSet
scdaMovCont.Fill(dsMovCont, strTabla)
sccnnConnection.Close()
Catch oSqlException As SqlException
If (sccnnConnection.State <> ConnectionState.Closed) Then
Try
sccnnConnection.Close()
Catch
End Try
End If
Throw New ApplicationException("Los registros no pudieron ser leidos debido a un error de base de datos.", oSqlException)
Catch ex As Exception
If (sccnnConnection.State <> ConnectionState.Closed) Then
Try
sccnnConnection.Close()
Catch
End Try
End If
Throw New ApplicationException("Los registros no pudieron ser leidos debido a un error de aplicación.", ex)
End Try
sccnnConnection.Dispose()
sccnnConnection = Nothing
Return dsMovCont
End Function