Visual Basic.NET - Valores Nulos en DATAGRIND

 
Vista:

Valores Nulos en DATAGRIND

Publicado por Marcela Soto (5 intervenciones) el 28/10/2014 00:42:21
Gracias a los que me han ayudado en el Temas anteriores ahora me encuentro con esto

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
Public Sub Insertar()
 
        Dim Ultimo As Integer
        Dim Fecha As String
        Dim Grupo As String
        Dim Lista As String
        Dim Numero As String
        Dim Monto As String
        Dim Ticket As String
        Dim Total As String
        For Each row As DataGridViewRow In GrdVenta.Rows
            If Not String.IsNullOrEmpty(row.Cells("Monto").FormattedValue.ToString()) Then
                    Ultimo = Convert.ToInt32(lblFinal.Text + 1)
                    Fecha = txtFecha.Text
                    Grupo = TxtGrupo.Text
                    Lista = TxtLista.Text
                    Monto = Convert.ToString(row.Cells("Monto").Value.ToString())
                    Numero = Convert.ToString(row.Cells("Numero").Value.ToString())
                    Dim valor As Integer = Numero
                    Numero = String.Format("{0:00}", valor)
                    Ticket = lblClave.Text
                    Total = Convert.ToInt32(lblTotal.Text)
                    Try
                        comandos = New OleDbCommand("INSERT INTO Venta (Ultimo,Fecha,Grupo,Lista, Numero, Monto,Ticket,Total)" & Chr(13) &
                                                        "VALUES (Ultimo,Fecha,Grupo,Lista, Numero, Monto,Ticket,Total)", conexion)
                        comandos.Parameters.AddWithValue("@Ultimo", Ultimo)
                        comandos.Parameters.AddWithValue("@Fecha", Fecha)
                        comandos.Parameters.AddWithValue("@Grupo", Grupo)
                        comandos.Parameters.AddWithValue("@Lista", Lista)
                        comandos.Parameters.AddWithValue("@Numero", Numero)
                        comandos.Parameters.AddWithValue("@Monto", Monto)
                        comandos.Parameters.AddWithValue("@Ticket", Ticket)
                        comandos.Parameters.AddWithValue("@Total", Total)
                        comandos.ExecuteNonQuery()
                    Catch ex As Exception
                        MsgBox("NO DEBE DEJAR EL NUMERO EN BLANCO", MsgBoxStyle.Critical)
                        GrdVenta.Focus()
                    End Try
            End If
 
        Next
    End Sub

Me sale que no controlo los nulos si dejo la casilla Numeros vacia lo corrego asi

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
Public Sub Insertar()
 
        Dim Ultimo As Integer
        Dim Fecha As String
        Dim Grupo As String
        Dim Lista As String
        Dim Numero As String
        Dim Monto As String
        Dim Ticket As String
        Dim Total As String
        For Each row As DataGridViewRow In GrdVenta.Rows
            If Not String.IsNullOrEmpty(row.Cells("Monto").FormattedValue.ToString()) Then
                If Not String.IsNullOrEmpty(row.Cells("Numero").FormattedValue.ToString()) Then
                    Ultimo = Convert.ToInt32(lblFinal.Text + 1)
                    Fecha = txtFecha.Text
                    Grupo = TxtGrupo.Text
                    Lista = TxtLista.Text
                    Monto = Convert.ToString(row.Cells("Monto").Value.ToString())
                    Numero = Convert.ToString(row.Cells("Numero").Value.ToString())
                    Dim valor As Integer = Numero
                    Numero = String.Format("{0:00}", valor)
                    Ticket = lblClave.Text
                    Total = Convert.ToInt32(lblTotal.Text)
                    Try
                        comandos = New OleDbCommand("INSERT INTO Venta (Ultimo,Fecha,Grupo,Lista, Numero, Monto,Ticket,Total)" & Chr(13) &
                                                        "VALUES (Ultimo,Fecha,Grupo,Lista, Numero, Monto,Ticket,Total)", conexion)
                        comandos.Parameters.AddWithValue("@Ultimo", Ultimo)
                        comandos.Parameters.AddWithValue("@Fecha", Fecha)
                        comandos.Parameters.AddWithValue("@Grupo", Grupo)
                        comandos.Parameters.AddWithValue("@Lista", Lista)
                        comandos.Parameters.AddWithValue("@Numero", Numero)
                        comandos.Parameters.AddWithValue("@Monto", Monto)
                        comandos.Parameters.AddWithValue("@Ticket", Ticket)
                        comandos.Parameters.AddWithValue("@Total", Total)
                        comandos.ExecuteNonQuery()
                    Catch ex As Exception
                        MsgBox("NO DEBE DEJAR EL NUMERO EN BLANCO", MsgBoxStyle.Critical)
                        GrdVenta.Focus()
                    End Try
                Else
                    Numero = Convert.ToString(row.Cells("Numero").Value = 0)
                End If
            End If
 
        Next
    End Sub

Pero me gustario que si dejo el la una celda de numero vacida me asigne el valor de 0 a esa casilla me podria ayudar la verdad es que soy muy nueva en este lenguaje Gracias por su ayuda
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

Valores Nulos en DATAGRIND

Publicado por Marcela Soto (5 intervenciones) el 28/10/2014 01:46:12
EN SI LO QUE PASA ES QUE SI EL VALOR DE LA COLUNMA NUMERO ES NULL SE DETIENE EL CICLO COMO AGO PARA ASIGNARLE 0 A NUMERO SI EL VALOR ES NULL

1
2
3
4
5
6
7
8
9
10
11
For Each row As DataGridViewRow In GrdVenta.Rows
	If Not String.IsNullOrEmpty(row.Cells("Monto").FormattedValue.ToString()) Then
		Cant = Convert.ToString(row.Cells("Monto").Value.ToString())
		Descp = Convert.ToString(row.Cells("Numero").Value.ToString())
		Dim valor As Integer = Descp
		Descp = String.Format("{0:00}", valor)
		esp = "   X   "
		'imprime una linea de descripcion
		Ticket1.AgregaArticulo(Cant, esp, Descp)
	End If
Next
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

Valores Nulos en DATAGRIND

Publicado por Marcela Soto (5 intervenciones) el 28/10/2014 02:42:07
Ya resuelto

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
For Each row As DataGridViewRow In GrdVenta.Rows
	If Not String.IsNullOrEmpty(row.Cells("Monto").FormattedValue.ToString()) Then
		If String.IsNullOrEmpty(row.Cells("Numero").FormattedValue.ToString()) Then
			Dim n = Convert.ToString("0")
			Cant = Convert.ToString(row.Cells("Monto").Value.ToString())
			Descp = n
			Dim valor As Integer = Descp
			Descp = String.Format("{0:00}", valor)
			esp = "   X   "
			Ticket1.AgregaArticulo(Cant, esp, Descp)
		Else
			Cant = Convert.ToString(row.Cells("Monto").Value.ToString())
			Descp = Convert.ToString(row.Cells("Numero").Value.ToString())
			Dim valor As Integer = Descp
			Descp = String.Format("{0:00}", valor)
			esp = "   X   "
			'imprime una linea de descripcion
			Ticket1.AgregaArticulo(Cant, esp, Descp)
		End If
	End If
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

Valores Nulos en DATAGRIND

Publicado por omar (128 intervenciones) el 28/10/2014 13:57:52
Usa
if is dbnull() then
'Si esta vacio
else

end if
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