Mostrar Mensajes

Esta sección te permite ver todos los posts escritos por este usuario. Ten en cuenta que sólo puedes ver los posts escritos en zonas a las que tienes acceso en este momento.


Temas - anmaroso

Páginas: [1]
1
Buenos días y saludos para tod@s.

Sumar los registros de una columna (Importe) que tengan el mismo valor de otra columna (nombre) y poner el valor de la suma en el último registro de mismo (nombre) en la columna (total). Lo mismo que agrupar por (nombre).

Paso el código.

Código: [Seleccionar]

 da.Fill(dt)
        ds.Tables.Add(dt)

        Dim vmi1 As Integer
        Dim vmt1 As String
        Dim vmt2 As String
        Dim vms1 As Single
        Dim vms2 As Single
        Dim fila As Integer = 0


        While fila <= dt.Rows.Count - 1
            vmt1 = dt.Rows(fila)(1)
            vms1 = 0.0
            vmt2 = ""
            Do While dt.Rows(fila)(1) = vmt1 And fila <= dt.Rows.Count - 1
                vms1 = vms1 + dt.Rows(fila)(2)
                If vmt2 = "" Then
                    vmt2 = dt.Rows(fila)(6)
                Else
                    vmt2 = vmt2 & "," & dt.Rows(fila)(6)
                End If
                dt.Rows(fila)(8) = dt.Rows(fila)(0)

                If fila = dt.Rows.Count - 1 Then
                    dt.Rows(fila)(3) = vms1
                    dt.Rows(fila)(7) = vmt2
                    vms2 = vms2 + vms1
                    Exit While
                Else
                    If fila < dt.Rows.Count - 1 Then
                        fila = fila + 1
                    End If
                End If
            Loop
            If fila < dt.Rows.Count - 1 Then
                fila = fila - 1
                dt.Rows(fila)(3) = vms1
                dt.Rows(fila)(7) = vmt2
                vms2 = vms2 + vms1
                fila = fila + 1
            End If
        End While


dt es un DataTabla.

He estado dándole mil vueltas y no lo conseguía . Ya sé que esta forma es a la antigua usanza... muy rudimentaria pero es de la única manera que lo he logrado.

No sé si habrá alguna forma de hacerlo más práctico y con menos código. Lo he intentado con el Grouping y no me funcionó, viene casi todo con Query y yo uso Acces.

De todas formas ahí queda por si le sirve a alguien.

Gracias y saludos.

2
Buenos días.

No me actualiza la base de datos con Visual Basic. Paso el código.

Código: [Seleccionar]

 If ds.HasChanges Then
            Try
                Me.Validate()
                dt.AcceptChanges()
                da.Update(dt)
                MsgBox("datos actualizados")
            Catch ex As Exception
                MsgBox("Update failed")
            End Try

            MsgBox(vms2)
        Else
            MsgBox("No hay modificación de registros")
        End If


dt es la tabla  Dim dt As DataTable
   
da el OleDbDataadapter Dim da As New OleDb.OleDbDataAdapter

Lo intento de mil maneras y no lo logro. algo hago mal pero no lo veo.


Gracias y Saludos.

3
Hola a tod@s, buenos días.

Tengo un fichero XML con todas las etiquetas bien esquematizadas.

Mi pregunta es cómo paso valores a las que lo requieren. o qué método es más sencillo para emitir ese fichero.

He leído que se puede hacer por WRITER o por diseño XLS pero la verdad es que no sé como seguir después de ordenar todas las etiquetas.

 Agradecería cualquier tipo de información al respecto.

Saludos.

4
Buenos días.

¿Es posible formatear la fecha de forma que el valor sea 2015-14-10T10:34:23.

(date1.ToString("s")) así no me funciona.

Gracias y saludos.

5
Hasta hace poco me funcionaba pero no sé que he hecho que ya no funciona y sin el valor de la variable no me deja seguir.

Paso el código por si hay alguna solución.

Código: [Seleccionar]
Public Class FTRANSF_C
    Public vff2 As Date
    Public Const vgf As Date = #1/1/1001#
    Dim strcnn As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
                           "Data Source=C:\GESTION\GESTION.mdb"
    Private Sub FTRANSF_C_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        vff2 = FTRANSF.vff
        MsgBox("Fecha seleccionada " & vff2, 1)
        FTRANSF.Close()

        vencimiento(vff1:=vff2)
        'DG1.DataSource = dst.Tables("Vencimientos").DefaultView
        'Dim vpi As Integer
        'vpi = DG1.RowCount
        'If vpi = 0 Then
        ' Dim vpt As String
        'Dim vpt1 As String
        ' Dim vpd As Single
        'Dim vpi1 As Integer = 0
        'For i = 1 To vpi
        'vpt = DG1.Rows(vpi1).Cells(1).Value
        '       While DG1.Rows(vpi1).Cells(1) = vpt
        '      End While
        'Next
        'DG1.Name = "Listado de Vencimientos"
        ' DG1.ReadOnly = True
        'DG1.DataSource = dst.Tables("Vencimientos").DefaultView
        'If DataRow = 0 Then 'DG1.RowCount = 0 Then
        'MsgBox("NO HAY REGISTROS")
        'Else
        'MsgBox("Si")
        'End If
        'End If
    End Sub

    Private Sub vencimiento(ByVal vff1 As Date)
        vff1 = vff2
        If vff1 > vgf Then
            Dim conexion As OleDb.OleDbConnection = _
            New OleDb.OleDbConnection(strcnn)
            Dim adaptador As OleDb.OleDbDataAdapter = _
            New OleDb.OleDbDataAdapter("SELECT TFACTURASR.VENCIMIENTO, " & _
                     "TPROVEEDORES.NOMBRE,TFACTURASR.IMPORTE,TFACTURASR.IMPORTET," & _
                     "TFACTURASR.FACTURANE,TFACTURASR.CONCEPTOP,TFCTURASR.FECHAE," & _
                     "TFACTURASR.FACTURANR,TFACTURASR.FECHAP " & _
                     "FROM TFACTURASR INNER JOIN TPROVEEDORES ON " & _
                     "TPROVEEDORES.CLAVE = TFACTURASR.CPROVEEDOR " & _
                     "WHERE TFACTURASR.VENCIMIENTO = # " & Format(vff1, "MM/DD/YYYY") & " # " & _
                     "AND TFACTURASR.NOPAGAR = 0 AND TFACTURASR.PAGADA = FALSE " & _
                     "AND TPROVEEDORES.NOPAGAR = 0 AND TFACTURASR.FPAGO LIKE '" & 4 & "%'" & _
                     "ORDER BY TFACTURASR.VENCIMIENTO, TPROVEEDORES.NOMBRE", conexion)

            Dim dst As DataSet = New DataSet
            Try
                conexion.Open()
                adaptador.Fill(dst, "Vencimientos")
                DG1.Name = "Listado de Vencimientos"
                'DG1.ReadOnly = True
                DG1.DataSource = dst.Tables("Vencimientos").DefaultView
                If DG1.RowCount = 0 Then
                    MsgBox("NO HAY REGISTROS")
                Else
                    MsgBox("Si")
                End If
                '  Vencimientos = dst.Tables(0)
            Catch ex As OleDb.OleDbException
                MsgBox("se ha producido una excepción: " + ex.Message, 16, Me.Text)
            Finally
                conexion.Close() 'conexion.Dispose()adaptador.Dispose(dst.Dispose())
            End Try
        End If
    End Sub

    Private Sub BS_DoubleClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BS.Click
        Me.Close()
    End Sub

End Class

6
Código: [Seleccionar]

Public Class FTRANSF_C
    Dim vpf1 As Date
    Dim strcnn As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
                           "Data Source=C:\GESTION\GESTION.mdb"
    Dim cnn As OleDb.OleDbConnection
    '    Dim orden As OleDb.OleDbCommand
    Dim da As OleDb.OleDbDataAdapter
    Dim ds As DataSet

    Private Sub FTRANSF_C_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        vpf1 = FTRANSF.vpf
        MsgBox(vpf1)
        FTRANSF.Close()
    End Sub

    Private Sub vencimiento(ByVal vpf1 As Date)
        cnn = New OleDb.OleDbConnection(strcnn)
        OleDbSelectCommand1.CommandText = "SELECT TFACTURASR.VENCIMIENTO, " & _
             "TPROVEEDORES.NOMBRE,TFACTURASR.IMPORTE,TFACTURASR.IMPORTET " & _
             "TFACTURASR.FACTURANE,TFACTURASR.CONCEPTOP,TFCTURASR.FECHAE, " & _
             "TFACTURASR.FACTURANR,TFACTURASR.FECHAP " & _
             "FROM TFACTURASR INNER JOIN TPROVEEDORES ON " & _
             "TPROVEEDORES.CLAVE = TFACTURASR.CPROVEEDOR " & _
             "WHERE TFACTURASR.VENCIMIENTO =" & vpf1 & " " & _
             "AND TFACTURASR.NOPAGAR = 0 AND TFACTURASR.PAGADA = FALSE " & _
             "AND TPROVEEDORES.NOPAGAR = 0 AND TFACTURASR.FPAGO LIKE '" & 4 & "%'" & _
             "ORDER BY TFACTURASR.VENCIMIENTO, TPROVEEDORES.NOMBRE"
        ds = New DataSet
        cnn.Open()
        da = New OleDb.OleDbDataAdapter
        OleDbSelectCommand1 = New OleDb.OleDbCommand
        OleDbUpdateCommand1 = New OleDb.OleDbCommand
        OleDbInsertCommand1 = New OleDb.OleDbCommand
        OleDbDeleteCommand1 = New OleDb.OleDbCommand
        da.SelectCommand = OleDbSelectCommand1
        da.UpdateCommand = OleDbUpdateCommand1
        da.InsertCommand = OleDbInsertCommand1
        da.DeleteCommand = OleDbDeleteCommand1
        OleDbSelectCommand1.Connection = OleDbConnection1
        OleDbUpdateCommand1.Connection = OleDbConnection1
        OleDbInsertCommand1.Connection = OleDbConnection1
        OleDbDeleteCommand1.Connection = OleDbConnection1
        da.Fill(ds, "TPROVEEDORES", "TFACTURASR")
        DG1.DataSource = ds.Tables("TPROVEEDORES", "TFACTURASR")
        DG1.Columns("VENCIMIENTO").HeaderText = "VENCIMIENTO"
        DG1.Columns("NOMBRE").HeaderText = "NOMBRE"
        DG1.Columns("IMPORTE").HeaderText = "IMPORTE"
        DG1.Columns("IMPORTET").HeaderText = "IMPORTET"
        DG1.Columns("FACTURANE").HeaderText = "FACTURANE"
        DG1.Columns("CONCEPTOP").HeaderText = "CONCEPTOP"
        DG1.Columns("FECHAE").HeaderText = "FECHAE"
        DG1.Columns("FACTURANR").HeaderText = "FACTURANR"
        DG1.Columns("FECHAP").HeaderText = "FECHAP"
        DG1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill
    End Sub

    Private Sub BS_DoubleClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BS.Click
        Me.Close()
    End Sub


End Class


Buenas tardes.
Quisiera saber si el código precitado es correcto para pasar datos a un DataGridView, basado en una consulta con variable incluida.
El código está basado siguiendo las instrucciones de un libro y a parte de que no me funciona, creo que es excesivo... tiene que haber algo más conciso.

Muchas gracias y saludos.

7
Me abre el MENU pero no se para, sigue y finaliza el proceso. ¿Qué puede estar ocurriendo?

Código: [Seleccionar]
Option Explicit On
Option Strict On
Imports System
Imports System.Object
Imports System.Data
Imports System.String
Imports Microsoft
Imports Microsoft.VisualBasic
Module Module1
    Public mfrm As MENU = New MENU()
    Sub Main()
        mfrm.Show()
    End Sub
 


8
Buenos días:

Soy un jubilado que pretende aprender Visual Basic NET pues de siempre me ha gustado la programación, lo hacía hace bastantes años con Open Acces en MS2. Ya sé que es un poco tarde pero ahora el tiempo me lo permite.

Mi lema es aprender con la práctica, así, en plan autodidacta, aprendí anteriormente, no obstante me leeré todos los manuales. Ya estoy leyendo un libro que compré.

Solo ruego un poco de respeto y paciencia.

Muchas gracias y saludos para tod@s.

Muchas gracias

Páginas: [1]

Sobre la educación, sólo puedo decir que es el tema más importante en el que nosotros, como pueblo, debemos involucrarnos.

Abraham Lincoln (1808-1865) Presidente estadounidense.

aprenderaprogramar.com: Desde 2006 comprometidos con la didáctica y divulgación de la programación

Preguntas y respuestas

¿Cómo establecer o cambiar la imagen asociada (avatar) de usuario?
  1. Inicia sesión con tu nombre de usuario y contraseña.
  2. Pulsa en perfil --> perfil del foro
  3. Elige la imagen personalizada que quieras usar. Puedes escogerla de una galería de imágenes o subirla desde tu ordenador.
  4. En la parte final de la página pulsa el botón "cambiar perfil".