Visual Basic.NET - MsgBox Luego de realizar consulta Sql

 
Vista:
sin imagen de perfil

MsgBox Luego de realizar consulta Sql

Publicado por Micesto (1 intervención) el 02/03/2018 02:10:58
Quiero que me muestre un msgbox cuando realiza correctamente la consulta y cuando esta falla
Soy nuevo en ámbito de la programación y se que tengo mil errores!

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
Public Sub EliminarBackoffice(ByVal sDias As String, ByVal mtzsn As String)
 
    Conectarbko()
    Dim comando As New OdbcCommand, filas As Integer
    Dim sql As String
    Dim fechatrans As String = Date.Now.ToString("yyyy")
 
    sql = "BACKUP DATABASE backoffice TO DISK = 'C:\CINET\HISTORICO" & fechatrans & ".Bak' WITH FORMAT, MEDIANAME = 'CINET',  NAME = 'Bkp Superparametrizador backoffice';  "
 
    comando.Connection = Conexion
    comando.CommandText = sql
 
 
    Try
        filas = comando.ExecuteNonQuery()
        MsgBox("BACKUP REALIZADO EN C:\ccc", MsgBoxStyle.Information)
    Catch ex As Exception
        filas = -1
        MsgBox("No se pudo realizar el Backup", MsgBoxStyle.Exclamation)
    End Try
    ''Ventas
    sql = "delete ventas_d from ventas_d d inner join ventas_e e on d.vene_numero=e.vene_numero and e.suc_codigo = d.suc_codigo and e.cbtee_codigo=d.cbtee_codigo where e.vene_Fecha <= getdate()-" & sDias & ";"""
    sql = "delete ventas_t from ventas_t t inner join ventas_e e on t.vene_numero=e.vene_numero and e.suc_codigo = t.suc_codigo and e.cbtee_codigo=t.cbtee_codigo where e.vene_Fecha <= getdate()-" & sDias & ";"""
    sql = "delete ventas_e where vene_fecha <= getdate()-" & sDias & ";"""
 
 
    comando.Connection = Conexion
    comando.CommandText = sql
    comando.CommandTimeout = 60 * 1000 * 60
 
    Try
        filas = comando.ExecuteNonQuery()
        MsgBox("Ventas Borradas", MsgBoxStyle.Information)
    Catch ex As Exception
        filas = -1
    End Try
 
    '' Varios
    sql = "delete asientos_d where asi_numero in (select asi_numero from asientos_e where asi_numero <> '0' and ASI_fecha <= getdate()-" & sDias & ";""delete asientos_e where asi_numero <> '0' and ASI_fecha <= getdate()-" & sDias & ";"""
    sql = "delete EGRESOS_D from EGRESOS_E e inner join egresos_d d on d.egre_numero = e.egre_numero and e.cbteeg_codigo = d.CBTEEG_CODIGO and e.CBTEEGSUC_CODIGO = d.CBTEEGSUC_CODIGO where e.egre_fecha <= getdate()-" & sDias & ";""delete EGRESOS_E where EGRE_FECHA <= getdate()-" & sDias & ";"""
    sql = "delete stock where ccst_fecha <= getdate()-" & sDias & ";"""
 
    Try
        filas = comando.ExecuteNonQuery()
        MsgBox("Asientos, Egresos y Stock borrados", MsgBoxStyle.Information)
    Catch ex As Exception
        filas = -1
    End Try
    '' Tarjetas
    sql = "delete LPOperaciones;delete LPLOTE"
 
    comando.Connection = Conexion
    comando.CommandText = sql
 
    Try
        filas = comando.ExecuteNonQuery()
        MsgBox("DATOS DE TARJETAS ELIMINADOS",MsgBoxStyle.Information)
    Catch ex As Exception
        filas = -1
        MsgBox("No se borraron datos de tarjetas", MsgBoxStyle.Exclamation)
    End Try
    ''Mostaza
    If mtzsn = "S" Then
 
 
        Try
            filas = comando.ExecuteNonQuery()
            MsgBox("Datos Mostaza eliminados", MsgBoxStyle.Information)
        Catch ex As Exception
            filas = -1
            MsgBox("No se pudieron borrar los datos de Mostaza", MsgBoxStyle.Exclamation)
        End Try
 
 
        sql = "delete cupredimido where vene_fecha <= getdate()-" & sDias & ";""delete VENTAS_PRM  where vpr_fecha <= getdate()-" & sDias & ";""delete librocaja where lica_fecha <= getdate()-" & sDias & ";"
        sql = "delete aya where aya_fecha <= getdate()-" & sDias & ";""delete zeta_e where  fecha  <= getdate()-" & sDias & ";"""
        sql = "delete auditoriaoperaciones;delete hparamloc;delete auditoria"
 
        comando.Connection = Conexion
        comando.CommandText = sql
        comando.CommandTimeout = 60 * 1000 * 60
 
        MsgBox("Limpieza de base realizada correctamente !!", MsgBoxStyle.Information)
        Form1.Show()
    Else
        MsgBox("Limpieza de base realizada correctamente", MsgBoxStyle.Information)
 
    End If
 
 
End Sub
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 giancarlo
Val: 377
Bronce
Ha mantenido su posición en Visual Basic.NET (en relación al último mes)
Gráfica de Visual Basic.NET

MsgBox Luego de realizar consulta Sql

Publicado por giancarlo (488 intervenciones) el 19/03/2018 23:10:18
el nonquery, devuelve cuantos valores han sido agregados o modificado, si tu comando se ejecutó correactmente, debe darte 1 a más como resultado(depende de tu comando), por ahí ya tienes una idea.

ya que usas try-cath, al dar error se ejecutará el bloque catch, ahí puedes poner un mensaje de error
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