Visual Basic.NET - como mostrar un dato de una tabla en una columna especifica de un datagrid

 
Vista:

como mostrar un dato de una tabla en una columna especifica de un datagrid

Publicado por Adalberto Cruz (2 intervenciones) el 24/01/2021 22:21:26
tengo un datagrid con 7 columnas ya creadas con sus respectivos nombres, ahora lo que necesitaria es poder haciendo un select a una tabla pasar los datos de una columna x de la tabla a una columna y del datagrid asi sucesivamente con las 7 columnas del select
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de Phil Rob
Val: 3.353
Oro
Ha mantenido su posición en Visual Basic.NET (en relación al último mes)
Gráfica de Visual Basic.NET

como mostrar un dato de una tabla en una columna especifica de un datagrid

Publicado por Phil Rob (1554 intervenciones) el 25/01/2021 07:53:02
Hola,

El código siguiente debería te ayudar :

1
2
3
4
5
6
7
8
9
10
11
12
Dim IndicioLinea As Integer
Dim IndicioColumna As Integer
 
' Con estos indicios, podemos para leer o escribir a los valores del DGV, con :   DataGridView1.Item(IndicioColumna, IndicioLinea).Value
 
' Por ejemplo, para copiar el DGV llenado con Integer en una Tabla de Integer (no he probado) :
        Dim Tabla(NombreLineaDGV, NombreColummaDGV) As integer
        For IndicioLinea = 0 To DataGridView1.Rows.Count - 1
          For IndicioColumna = 0 To DataGridView1.Columns.Count - 1
                Tabla(IndicioLinea, IndicioColumna) = DataGridView1.Item(IndicioColumna, IndicioLinea).Value
          Next
        Next

Que tenga un buen día ...
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
1
Comentar

como mostrar un dato de una tabla en una columna especifica de un datagrid

Publicado por Adalberto Cruz (2 intervenciones) el 27/01/2021 00:59:36
Muchas gracias hermano por tu ayuda

si no es mucha molestia me podrías ayudar con otro tema hermano.

El tema es que necesito sumar 7 columnas de un Datagridview en el siguiente código me da error de ( no se puede convertir en el tipo 'DBNull'.)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
Dim Total1 As Double
Dim Total2 As Double
Dim Total3 As Double
Dim Total4 As Double
Dim Total5 As Double
Dim Total6 As Double
Dim Total7 As Double
 
Dim cont As Integer = 0 'PARA CONTADOR DE PARTIDAS
Dim Col As Integer = Me.DataGridView1.CurrentCell.ColumnIndex
For Each row As DataGridViewRow In Me.DataGridView1.Rows
 
If (row.Cells(0).Value Is Nothing) Then
    Total1 = Total1 + 0
Else
    Total1 += Math.Round(Val(row.Cells(0).Value), 2) 'ROW.CELLS (NUMERO DE LA COLUMNA A SUMAR).VALUE
    End If
 
    If (row.Cells(1).Value Is Nothing) Then
        Total2 = Total2 + 0
    Else
        Total2 += Math.Round(Val(row.Cells(1).Value), 2) 'ROW.CELLS (NUMERO DE LA COLUMNA A SUMAR).VALUE
    End If
 
    If (row.Cells(2).Value Is Nothing) Then
        Total3 = Total3 + 0
    Else
        Total3 += Math.Round(Val(row.Cells(2).Value), 2) 'ROW.CELLS (NUMERO DE LA COLUMNA A SUMAR).VALUE
    End If
 
    If (row.Cells(3).Value Is Nothing) Then
        Total4 = Total4 + 0
    Else
        Total4 += Math.Round(Val(row.Cells(3).Value), 2) 'ROW.CELLS (NUMERO DE LA COLUMNA A SUMAR).VALUE
    End If
 
    If (row.Cells(4).Value Is Nothing) Then
        Total5 = Total5 + 0
    Else
        Total5 += Math.Round(Val(row.Cells(4).Value), 2) 'ROW.CELLS (NUMERO DE LA COLUMNA A SUMAR).VALUE
    End If
 
    If (row.Cells(5).Value Is Nothing) Then
        Total6 = Total6 + 0
    Else
        Total6 += Math.Round(Val(row.Cells(5).Value), 2) 'ROW.CELLS (NUMERO DE LA COLUMNA A SUMAR).VALUE
    End If
 
    If (row.Cells(6).Value Is Nothing) Then
        Total7 = Total7 + 0
    Else
        Total7 += Math.Round(Val(row.Cells(6).Value), 2) 'ROW.CELLS (NUMERO DE LA COLUMNA A SUMAR).VALUE
    End If
 
 
Next
 
ttarjeta.Text = Total1.ToString
tdepositord.Text = Total2.ToString
tdepositous.Text = Total3.ToString
tcheque.Text = Total4.ToString
tchequef.Text = Total5.ToString
tnc.Text = Total6.ToString
treembolso.Text = Total7.ToString
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
Imágen de perfil de Adalberto
Val: 11
Ha aumentado su posición en 34 puestos en Visual Basic.NET (en relación al último mes)
Gráfica de Visual Basic.NET

como mostrar un dato de una tabla en una columna especifica de un datagrid

Publicado por Adalberto (2 intervenciones) el 27/01/2021 02:07:57
Te comento hermano que lo pude solucionar utilice la condicional if isdbnull() ira como quedo el codigo y funciona perfecto

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
Dim Total1 As Double
Dim Total2 As Double
Dim Total3 As Double
Dim Total4 As Double
Dim Total5 As Double
Dim Total6 As Double
Dim Total7 As Double
 
Dim cont As Integer = 0 'PARA CONTADOR DE PARTIDAS
Dim Col As Integer = Me.DataGridView1.CurrentCell.ColumnIndex
For Each row As DataGridViewRow In Me.DataGridView1.Rows
 
 
 
    If IsDBNull(row.Cells(0).Value) Then
 
        Total1 = Total1 + 0
 
    Else
 
        Total1 += Math.Round(Val(row.Cells(0).Value), 2) 'ROW.CELLS (NUMERO DE LA COLUMNA A SUMAR).VALUE
 
    End If
 
    If IsDBNull(row.Cells(1).Value) Then
 
        Total2 = Total2 + 0
 
    Else
 
        Total2 += Math.Round(Val(row.Cells(1).Value), 2) 'ROW.CELLS (NUMERO DE LA COLUMNA A SUMAR).VALUE
 
    End If
 
    If IsDBNull(row.Cells(2).Value) Then
 
        Total3 = Total3 + 0
 
    Else
 
        Total3 += Math.Round(Val(row.Cells(2).Value), 2) 'ROW.CELLS (NUMERO DE LA COLUMNA A SUMAR).VALUE
 
    End If
 
    If IsDBNull(row.Cells(3).Value) Then
 
        Total4 = Total4 + 0
 
    Else
 
        Total4 += Math.Round(Val(row.Cells(3).Value), 2) 'ROW.CELLS (NUMERO DE LA COLUMNA A SUMAR).VALUE
 
    End If
 
    If IsDBNull(row.Cells(4).Value) Then
 
        Total5 = Total5 + 0
 
    Else
 
        Total5 += Math.Round(Val(row.Cells(4).Value), 2) 'ROW.CELLS (NUMERO DE LA COLUMNA A SUMAR).VALUE
 
    End If
 
    If IsDBNull(row.Cells(5).Value) Then
 
        Total6 = Total6 + 0
 
    Else
 
        Total6 += Math.Round(Val(row.Cells(5).Value), 2) 'ROW.CELLS (NUMERO DE LA COLUMNA A SUMAR).VALUE
 
    End If
 
    If IsDBNull(row.Cells(6).Value) Then
 
        Total7 = Total7 + 0
 
    Else
 
        Total7 += Math.Round(Val(row.Cells(6).Value), 2) 'ROW.CELLS (NUMERO DE LA COLUMNA A SUMAR).VALUE
 
    End If
 
Next
 
ttarjeta.Text = Total1.ToString
tdepositord.Text = Total2.ToString
tdepositous.Text = Total3.ToString
tcheque.Text = Total4.ToString
tchequef.Text = Total5.ToString
tnc.Text = Total6.ToString
treembolso.Text = Total7.ToString

espero le sirva el contenido a alguien mas, de nuevo muchas gracias por su ayuda hermano
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
Imágen de perfil de Phil Rob
Val: 3.353
Oro
Ha mantenido su posición en Visual Basic.NET (en relación al último mes)
Gráfica de Visual Basic.NET

como mostrar un dato de una tabla en una columna especifica de un datagrid

Publicado por Phil Rob (1554 intervenciones) el 27/01/2021 07:43:43
Hola,

Quizá debes reemplazar Is Nothing por = String.Empty.

Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar