Foros del Web » Programación para mayores de 30 ;) » .NET »

[SOLUCIONADO] filas y columnas de la tabla

Estas en el tema de filas y columnas de la tabla en el foro de .NET en Foros del Web. Hola, estoy programando en vb.net y tengo el siguiente problema. si pongo lo siguiente, la tabla se pone correctamente: @import url("http://static.forosdelweb.com/clientscript/vbulletin_css/geshi.css"); Código vb.net: Ver original ...
  #1 (permalink)  
Antiguo 16/04/2013, 01:59
 
Fecha de Ingreso: abril-2012
Mensajes: 449
Antigüedad: 12 años, 1 mes
Puntos: 7
Exclamación filas y columnas de la tabla

Hola,
estoy programando en vb.net y tengo el siguiente problema.

si pongo lo siguiente, la tabla se pone correctamente:
Código vb.net:
Ver original
  1. Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  2.         Dim conn As New MySqlConnection
  3.         conn.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings("conexionMySQL").ConnectionString
  4.         Dim mysql_comando As New MySqlCommand("Select noperario,operario,inicio from cdp_operaciones where noperario = 9152", conn)
  5.         Dim reader As MySqlDataReader
  6.         Dim da As New MySqlDataAdapter(mysql_comando)
  7.         Dim numoperario As Integer
  8.         Dim nombre, mes, fechaActual, reglaplantrabajo, mesActual, anoActual, fecha, horas As String
  9.         Dim inicio As Date
  10.         Dim objRow As New TableRow()
  11.         Dim objCell1, objCell2, objCell3, objCell4, objCell5, objCell6, objCell7, objCell8 As New TableCell()
  12.  
  13.         fechaActual = Now.Date
  14.         mesActual = Month(fechaActual)
  15.         anoActual = Year(fechaActual)
  16.         fecha = mesActual + "/" + anoActual
  17.  
  18.         Try
  19.                 Using conn
  20.                     conn.Open()
  21.                     With mysql_comando
  22.                         reader = .ExecuteReader()
  23.                         While reader.Read()
  24.                             numoperario = reader.GetValue(0)
  25.                             nombre = reader.GetValue(1)
  26.                             mes = fecha
  27.                             inicio = reader.GetValue(2)
  28.                             objCell1.Controls.Add(New LiteralControl(numoperario))
  29.                             objCell2.Controls.Add(New LiteralControl(nombre))
  30.                             objCell3.Controls.Add(New LiteralControl(mes))
  31.                             objCell4.Controls.Add(New LiteralControl(inicio))
  32.                             objRow.Cells.Add(objCell1)
  33.                             objRow.Cells.Add(objCell2)
  34.                             objRow.Cells.Add(objCell3)
  35.                             objRow.Cells.Add(objCell4)
  36.                         End While
  37.                         .Dispose()
  38.                     End With
  39.                 End Using
  40.             Catch ex As Exception
  41.                 MsgBox("Error en BD" & Chr(13) & Chr(13) & ex.Message)
  42.             Finally
  43.                 conn.Close()
  44.                 conn.Dispose()
  45.             End Try
  46.             Table1.Rows.Add(objRow)
  47.     End Sub

Pero si ya introduzco mas cosas, como la que se ven en el codigo de abajo, se me descuadra todo y el nombre aparece donde tendria que aparece el mes, es decir, en la celda 3.
Código vb.net:
Ver original
  1. Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  2.         Dim conn As New MySqlConnection
  3.         conn.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings("conexionMySQL").ConnectionString
  4.         Dim mysql_comando As New MySqlCommand("Select noperario,operario,inicio from cdp_operaciones where noperario = 9152", conn)
  5.         Dim reader As MySqlDataReader
  6.         Dim da As New MySqlDataAdapter(mysql_comando)
  7.         Dim numoperario, longitud1, longitud2, i, j As Integer
  8.         Dim nombre, mes, fechaActual, reglaplantrabajo, mesActual, anoActual, fecha, horas, tprX, tiempotprX,tpr29, tpr30, tpr31 As String
  9.         Dim inicio As Date
  10.         Dim tiempotpr01, tiempotpr02, tiempotpr03, tiempotpr04, tiempotpr05, tiempotpr06, tiempotpr07, tiempotpr08, tiempotpr09, tiempotpr10, tiempotpr11, tiempotpr12, tiempotpr13, tiempotpr14, tiempotpr15, tiempotpr16, tiempotpr17, tiempotpr18, tiempotpr19, tiempotpr20, tiempotpr21, tiempotpr22, tiempotpr23, tiempotpr24, tiempotpr25, tiempotpr26, tiempotpr27, tiempotpr28, tiempotpr29, tiempotpr30, tiempotpr31, tiempoteorico  As Decimal
  11.         Dim valoresarray1, valoresarray2 As String()
  12.         Dim objRow As New TableRow()
  13.         Dim objCell1, objCell2, objCell3, objCell4, objCell5, objCell6, objCell7, objCell8 As New TableCell()
  14.  
  15.         fechaActual = Now.Date
  16.         mesActual = Month(fechaActual)
  17.         anoActual = Year(fechaActual)
  18.         fecha = mesActual + "/" + anoActual
  19.         i = 0
  20.         j = 0
  21.         tiempoteorico = 0
  22.  
  23.         valoresarray1 = calculoFechaHorasReales(numoperario, fechaActual)
  24.         longitud1 = valoresarray1.Length
  25.         reglaplantrabajo = calculoReglaPlanTrabajo(numoperario, fechaActual)
  26.         valoresarray2 = calculoPeriodosTrabajo(reglaplantrabajo, fechaActual)
  27.         longitud2 = valoresarray2.Length
  28.  
  29.         For i = 0 To longitud1 - 1
  30.             Try
  31.                 Using conn
  32.                     conn.Open()
  33.                     With mysql_comando
  34.                         reader = .ExecuteReader()
  35.                         While reader.Read()
  36.                             numoperario = reader.GetValue(0)
  37.                             nombre = reader.GetValue(1)
  38.                             mes = fecha
  39.                             inicio = reader.GetValue(2)
  40.                             objCell1.Controls.Add(New LiteralControl(numoperario))
  41.                             objCell2.Controls.Add(New LiteralControl(nombre))
  42.                             objCell3.Controls.Add(New LiteralControl(mes))
  43.                             objCell4.Controls.Add(New LiteralControl(inicio))
  44.                             objRow.Cells.Add(objCell1)
  45.                             objRow.Cells.Add(objCell2)
  46.                             objRow.Cells.Add(objCell3)
  47.                             objRow.Cells.Add(objCell4)
  48.                         End While
  49.                         .Dispose()
  50.                     End With
  51.  
  52.                     objCell5.Controls.Add(New LiteralControl("Capturadas"))
  53.                     objRow.Cells.Add(objCell5) 'porcentaje horas capturas
  54.                     horas = calcularHorasDia(valoresarray1(i))
  55.                     objCell6.Controls.Add(New LiteralControl(horas))
  56.                     objRow.Cells.Add(objCell6)
  57.                     objCell7.Controls.Add(New LiteralControl("%"))
  58.                     objRow.Cells.Add(objCell7) 'porcentaje horas reales
  59.  
  60.                     tpr29 = valoresarray2(28)
  61.                     tpr30 = valoresarray2(29)
  62.                     tpr31 = valoresarray2(30)
  63.                     tiempotpr01 = calcularTiempoTeoricoDia(valoresarray2(0))
  64.                     tiempotpr02 = calcularTiempoTeoricoDia(valoresarray2(1))
  65.                     tiempotpr03 = calcularTiempoTeoricoDia(valoresarray2(2))
  66.                     tiempotpr04 = calcularTiempoTeoricoDia(valoresarray2(3))
  67.                     tiempotpr05 = calcularTiempoTeoricoDia(valoresarray2(4))
  68.                     tiempotpr06 = calcularTiempoTeoricoDia(valoresarray2(5))
  69.                     tiempotpr07 = calcularTiempoTeoricoDia(valoresarray2(6))
  70.                     tiempotpr08 = calcularTiempoTeoricoDia(valoresarray2(7))
  71.                     tiempotpr09 = calcularTiempoTeoricoDia(valoresarray2(8))
  72.                     tiempotpr10 = calcularTiempoTeoricoDia(valoresarray2(9))
  73.                     tiempotpr11 = calcularTiempoTeoricoDia(valoresarray2(10))
  74.                     tiempotpr12 = calcularTiempoTeoricoDia(valoresarray2(11))
  75.                     tiempotpr13 = calcularTiempoTeoricoDia(valoresarray2(12))
  76.                     tiempotpr14 = calcularTiempoTeoricoDia(valoresarray2(13))
  77.                     tiempotpr15 = calcularTiempoTeoricoDia(valoresarray2(14))
  78.                     tiempotpr16 = calcularTiempoTeoricoDia(valoresarray2(15))
  79.                     tiempotpr17 = calcularTiempoTeoricoDia(valoresarray2(16))
  80.                     tiempotpr18 = calcularTiempoTeoricoDia(valoresarray2(17))
  81.                     tiempotpr19 = calcularTiempoTeoricoDia(valoresarray2(18))
  82.                     tiempotpr20 = calcularTiempoTeoricoDia(valoresarray2(19))
  83.                     tiempotpr21 = calcularTiempoTeoricoDia(valoresarray2(20))
  84.                     tiempotpr22 = calcularTiempoTeoricoDia(valoresarray2(21))
  85.                     tiempotpr23 = calcularTiempoTeoricoDia(valoresarray2(22))
  86.                     tiempotpr24 = calcularTiempoTeoricoDia(valoresarray2(23))
  87.                     tiempotpr25 = calcularTiempoTeoricoDia(valoresarray2(24))
  88.                     tiempotpr26 = calcularTiempoTeoricoDia(valoresarray2(25))
  89.                     tiempotpr27 = calcularTiempoTeoricoDia(valoresarray2(26))
  90.                     tiempotpr28 = calcularTiempoTeoricoDia(valoresarray2(27))
  91.                     If tpr29 <> " " Then
  92.                         tiempotpr29 = calcularTiempoTeoricoDia(valoresarray2(28))
  93.                     End If
  94.                     If tpr30 <> " " Then
  95.                         tiempotpr30 = calcularTiempoTeoricoDia(valoresarray2(29))
  96.                     End If
  97.                     If tpr31 <> " " Then
  98.                         tiempotpr31 = calcularTiempoTeoricoDia(valoresarray2(30))
  99.                     End If
  100.  
  101.                     tiempoteorico = tiempotpr01 + tiempotpr02 + tiempotpr03 +    tiempotpr04 + tiempotpr05 + tiempotpr06 + tiempotpr07 + tiempotpr08 + tiempotpr09 + tiempotpr10 + tiempotpr11 + tiempotpr12 + tiempotpr13 + tiempotpr14 + tiempotpr15 + tiempotpr16 + tiempotpr17 + tiempotpr18 + tiempotpr19 + tiempotpr20 + tiempotpr21 + tiempotpr22 + tiempotpr23 + tiempotpr24 + tiempotpr25 + tiempotpr26 + tiempotpr27 + tiempotpr28 + tiempotpr29 + tiempotpr30 + tiempotpr31
  102.                     objCell8.Controls.Add(New LiteralControl("tiempoteorico"))
  103.                     objRow.Cells.Add(objCell8) 'horas teoricas
  104.                 End Using
  105.             Catch ex As Exception
  106.                 MsgBox("Error en BD" & Chr(13) & Chr(13) & ex.Message)
  107.             Finally
  108.                 conn.Close()
  109.                 conn.Dispose()
  110.             End Try
  111.             Table1.Rows.Add(objRow)
  112.         Next
  113.     End Sub

Alguien me puede echar una mano?
__________________
Gracias por todo;

Un saludo
  #2 (permalink)  
Antiguo 18/04/2013, 02:58
 
Fecha de Ingreso: abril-2012
Mensajes: 449
Antigüedad: 12 años, 1 mes
Puntos: 7
Respuesta: filas y columnas de la tabla

Solucionado. La solución era el crear los objrow y objcell dentro del try para que cada vez que tenga que volver a hacer el try se creen objrow y objcell nuevos. Os dejo el código para que podais verlo mejor, y por si a alguien le sirve.

Código vb.net:
Ver original
  1. Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  2.         Dim conn As New MySqlConnection
  3.         conn.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings("conexionMySQL").ConnectionString
  4.         Dim mysql_comando As New MySqlCommand("Select distinct noperario,operario from cdp_operaciones where noperario = 2177", conn)
  5.         Dim reader As MySqlDataReader
  6.         Dim da As New MySqlDataAdapter(mysql_comando)
  7.         Dim numoperario, longitud1, longitud2, longitud3, longitud4, i, j, tiempoteorico, totalCapturadas, capturadas As Integer
  8.         Dim nombre, mes, fechaActual, reglaplantrabajo, mesActual, anoActual, fecha, horas As String
  9.         Dim tpr29, tpr30, tpr31 As String
  10.         Dim tiempotprX As Integer
  11.         Dim valoresarray1, valoresarray2, valoresarray3, valoresarray4 As String()
  12.         Dim objRow As New TableRow()
  13.         fechaActual = Now.Date
  14.         mesActual = Month(fechaActual)
  15.         anoActual = Year(fechaActual)
  16.         fecha = mesActual + "/" + anoActual
  17.         i = 0
  18.         j = 0
  19.  
  20.         valoresarray1 = calculoFechaHorasReales(numoperario, fechaActual)
  21.         longitud1 = valoresarray1.Length
  22.         reglaplantrabajo = calculoReglaPlanTrabajo(numoperario, fechaActual)
  23.         valoresarray2 = calculoPeriodosTrabajo(reglaplantrabajo, fechaActual)
  24.         longitud2 = valoresarray2.Length
  25.  
  26.         For i = 0 To longitud1 - 1
  27.             tiempoteorico = 0
  28.             Try
  29.                 objRow = New TableRow
  30.                 Dim objCell1, objCell2, objCell3, objCell4, objCell5, objCell6, objCell7, objCell8 As New TableCell()
  31.                 Using conn
  32.                     conn.Open()
  33.                     With mysql_comando
  34.                         reader = .ExecuteReader()
  35.                         While reader.Read()
  36.                             numoperario = reader.GetValue(0)
  37.                             nombre = reader.GetValue(1)
  38.                             mes = fecha
  39.                             objCell1.Controls.Add(New LiteralControl(numoperario))
  40.                             objCell1.HorizontalAlign = HorizontalAlign.Center
  41.                             objCell2.Controls.Add(New LiteralControl(nombre))
  42.                             objCell2.HorizontalAlign = HorizontalAlign.Center
  43.                             'objCell3.Controls.Add(New LiteralControl(mes))
  44.                             objCell3.Controls.Add(New LiteralControl(valoresarray1(i)))
  45.                             objCell3.HorizontalAlign = HorizontalAlign.Center
  46.                             objRow.Cells.Add(objCell1)
  47.                             objRow.Cells.Add(objCell2)
  48.                             objRow.Cells.Add(objCell3)
  49.                         End While
  50.                         .Dispose()
  51.                     End With                  
  52.                     objCell5.Controls.Add(New LiteralControl("%"))
  53.                     objCell5.HorizontalAlign = HorizontalAlign.Center
  54.                     objRow.Cells.Add(objCell5)
  55.                     horas = calcularHorasDia(valoresarray1(i))
  56.                     Dim longitud5, longitud6, longitud7 As Integer
  57.                     Dim h, minCortar, min, s, horasdia As String
  58.                     longitud5 = horas.Length
  59.                     If longitud5 = 5 Then
  60.                         h = horas.Substring(0, 1)
  61.                         minCortar = horas.Substring(0, 3)
  62.                         longitud6 = minCortar.Length
  63.                         min = Right(minCortar, longitud6 - 1)
  64.                         s = Right(horas, longitud5 - 3)
  65.                         horasdia = h + ":" + min + ":" + s
  66.                     ElseIf longitud5 = 6 Then
  67.                         h = horas.Substring(0, 2)
  68.                         minCortar = horas.Substring(0, 4)
  69.                         longitud6 = minCortar.Length
  70.                         min = Right(minCortar, longitud6 - 2)
  71.                         s = Right(horas, longitud5 - 4)
  72.                         horasdia = h + ":" + min + ":" + s
  73.                     End If
  74.                     objCell6.Controls.Add(New LiteralControl(horasdia))
  75.                     'objCell6.Controls.Add(New LiteralControl("horasReales"))
  76.                     objCell6.HorizontalAlign = HorizontalAlign.Center
  77.                     objRow.Cells.Add(objCell6)
  78.  
  79.                     objCell7.Controls.Add(New LiteralControl("%"))
  80.                     objCell7.HorizontalAlign = HorizontalAlign.Center
  81.                     objRow.Cells.Add(objCell7) 'porcentaje horas reales
  82.  
  83.                     Dim long1, long2 As Integer
  84.                     Dim ano, mesCortar, mes1, dia, fechaformato As String
  85.  
  86.                     long1 = valoresarray1(i).Length
  87.                     dia = Right(valoresarray1(i), longitud1 - 8)
  88.  
  89.                     If dia = "01" Then
  90.                         tiempotprX = calcularTiempoTeoricoDia(valoresarray2(0))
  91.                     ElseIf dia = "02" Then
  92.                         tiempotprX = calcularTiempoTeoricoDia(valoresarray2(1))
  93.                     ElseIf dia = "03" Then
  94.                         tiempotprX = calcularTiempoTeoricoDia(valoresarray2(2))
  95.                     ElseIf dia = "04" Then
  96.                         tiempotprX = calcularTiempoTeoricoDia(valoresarray2(3))
  97.                     ElseIf dia = "05" Then
  98.                         tiempotprX = calcularTiempoTeoricoDia(valoresarray2(4))
  99.                     ElseIf dia = "06" Then
  100.                         tiempotprX = calcularTiempoTeoricoDia(valoresarray2(5))
  101.                     ElseIf dia = "07" Then
  102.                         tiempotprX = calcularTiempoTeoricoDia(valoresarray2(6))
  103.                     ElseIf dia = "08" Then
  104.                         tiempotprX = calcularTiempoTeoricoDia(valoresarray2(7))
  105.                     ElseIf dia = "09" Then
  106.                         tiempotprX = calcularTiempoTeoricoDia(valoresarray2(8))
  107.                     ElseIf dia = "10" Then
  108.                         tiempotprX = calcularTiempoTeoricoDia(valoresarray2(9))
  109.                     ElseIf dia = "11" Then
  110.                         tiempotprX = calcularTiempoTeoricoDia(valoresarray2(10))
  111.                     ElseIf dia = "12" Then
  112.                         tiempotprX = calcularTiempoTeoricoDia(valoresarray2(11))
  113.                     ElseIf dia = "13" Then
  114.                         tiempotprX = calcularTiempoTeoricoDia(valoresarray2(12))
  115.                     ElseIf dia = "14" Then
  116.                         tiempotprX = calcularTiempoTeoricoDia(valoresarray2(13))
  117.                     ElseIf dia = "15" Then
  118.                         tiempotprX = calcularTiempoTeoricoDia(valoresarray2(14))
  119.                     ElseIf dia = "16" Then
  120.                         tiempotprX = calcularTiempoTeoricoDia(valoresarray2(15))
  121.                     ElseIf dia = "17" Then
  122.                         tiempotprX = calcularTiempoTeoricoDia(valoresarray2(16))
  123.                     ElseIf dia = "18" Then
  124.                         tiempotprX = calcularTiempoTeoricoDia(valoresarray2(17))
  125.                     ElseIf dia = "19" Then
  126.                         tiempotprX = calcularTiempoTeoricoDia(valoresarray2(18))
  127.                     ElseIf dia = "20" Then
  128.                         tiempotprX = calcularTiempoTeoricoDia(valoresarray2(19))
  129.                     ElseIf dia = "21" Then
  130.                         tiempotprX = calcularTiempoTeoricoDia(valoresarray2(20))
  131.                     ElseIf dia = "22" Then
  132.                         tiempotprX = calcularTiempoTeoricoDia(valoresarray2(21))
  133.                     ElseIf dia = "23" Then
  134.                         tiempotprX = calcularTiempoTeoricoDia(valoresarray2(22))
  135.                     ElseIf dia = "24" Then
  136.                         tiempotprX = calcularTiempoTeoricoDia(valoresarray2(23))
  137.                     ElseIf dia = "25" Then
  138.                         tiempotprX = calcularTiempoTeoricoDia(valoresarray2(24))
  139.                     ElseIf dia = "26" Then
  140.                         tiempotprX = calcularTiempoTeoricoDia(valoresarray2(25))
  141.                     ElseIf dia = "27" Then
  142.                         tiempotprX = calcularTiempoTeoricoDia(valoresarray2(26))
  143.                     ElseIf dia = "28" Then
  144.                         tiempotprX = calcularTiempoTeoricoDia(valoresarray2(27))
  145.                     ElseIf dia = "29" Then
  146.                         If tpr29 <> " " Then
  147.                             tiempotprX = calcularTiempoTeoricoDia(valoresarray2(28))
  148.                         End If
  149.                     ElseIf dia = "30" Then
  150.                         If tpr30 <> " " Then
  151.                             tiempotprX = calcularTiempoTeoricoDia(valoresarray2(29))
  152.                         End If
  153.                     ElseIf dia = "31" Then
  154.                         If tpr31 <> " " Then
  155.                             tiempotprX = calcularTiempoTeoricoDia(valoresarray2(30))
  156.                         End If
  157.                     End If
  158.  
  159.                     tiempoteorico = tiempotprX
  160.                     objCell8.Controls.Add(New LiteralControl(tiempoteorico))
  161.                     objCell8.HorizontalAlign = HorizontalAlign.Center
  162.                     objRow.Cells.Add(objCell8) 'horas teoricas
  163.                 End Using
  164.             Catch ex As Exception
  165.                 MsgBox("Error en BD" & Chr(13) & Chr(13) & ex.Message)
  166.             Finally
  167.                 conn.Close()
  168.                 conn.Dispose()
  169.             End Try
  170.             Table1.Rows.Add(objRow)
  171.         Next
  172.     End Sub


Un saludo
__________________
Gracias por todo;

Un saludo

Etiquetas: bd, columnas, conexion, filas, sql, tabla, vb
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 23:29.