Problema en Visual Basic
Publicado por Alejandro (2 intervenciones) el 15/08/2018 01:44:44
Estoy haciendo un programa en Visual Basic 2008, pero me da un problema al ingresar datos. "A first chance exception of type 'System.Data.Odbc.OdbcException' occurred in System.Data.dll
"
Pero si reinicio la Pc, e ingreso datos la primera vez si me pemite. dejo en comentarios el codigo
Por cierto Estoy trabajando con Informix
"
Pero si reinicio la Pc, e ingreso datos la primera vez si me pemite. dejo en comentarios el codigo
Por cierto Estoy trabajando con Informix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
Imports System.Data.Odbc
Module ConexionODBC
Public conectar As New Odbc.OdbcConnection
Public comando As New OdbcCommand
Public Sub conecta()
Try
conectar.ConnectionString = "FileDSN=" & Application.StartupPath & "\coso;UID=root;PWD=root"
comando.Connection = conectar
conectar.Open()
Catch ex As Exception
MsgBox("Error al conectarse con la base de datos")
conectar.Close()
End Try
End Sub
Public Sub cerrar()
conectar.Close()
End Sub
End Module
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
Imports System.Text.RegularExpressions
Public Class Persona
Dim Sql As String
Dim dr As Odbc.OdbcDataReader
Dim valido As Boolean
Function verificaDatosNumericos() As Boolean
If Not IsNumeric(Me.txtCI.Text) Then
MsgBox("El campo requiere un valor numerico")
Return False
End If
If Not IsNumeric(Me.txtTelefono.Text) Then
MsgBox("El campo requiere un valor numerico")
Return False
End If
Return True
End Function
Function verificaLetras() As Boolean
If Not IsNumeric(Me.txtNombre.Text) Then
MsgBox("El campo no puede contener un valor numerico")
Return False
End If
If IsNumeric(Me.txtApellido.Text) Then
MsgBox("El campo no puede contener un valor numerico")
Return False
End If
Return True
End Function
Private Sub btnValidar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
If verificaDatosNumericos() = True And verificaLetras() = True Then
MsgBox("Todo correcto")
btnIngresar.Enabled = True
End If
End Sub
Private Sub txtCI_KeyPress(ByVal sender As Object, _
ByVal e As KeyPressEventArgs) Handles txtCI.KeyPress
Dim re As New Regex("[^0-9_\-\b]", RegexOptions.IgnoreCase)
e.Handled = re.IsMatch(e.KeyChar)
End Sub
Private Sub txtTelefono_KeyPress(ByVal sender As Object, _
ByVal e As KeyPressEventArgs) Handles txtTelefono.KeyPress
Dim re As New Regex("[^0-9_\-\b]", RegexOptions.IgnoreCase)
e.Handled = re.IsMatch(e.KeyChar)
End Sub
Private Sub txtNombre_KeyPress(ByVal sender As Object, _
ByVal e As KeyPressEventArgs) Handles txtNombre.KeyPress
Dim re As New Regex("[^a-z_\-\b]", RegexOptions.IgnoreCase)
e.Handled = re.IsMatch(e.KeyChar)
End Sub
Private Sub txtApellido_KeyPress(ByVal sender As Object, _
ByVal e As KeyPressEventArgs) Handles txtApellido.KeyPress
Dim re As New Regex("[^a-z_\-\b]", RegexOptions.IgnoreCase)
e.Handled = re.IsMatch(e.KeyChar)
End Sub
Private Sub btnLimpiar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLimpiar.Click
Call Limpiar(Me)
End Sub
Sub Limpiar(ByVal c1 As Control)
For Each c As Control In c1.Controls
If TypeOf c Is TextBox Then
c.Text = "" ' eliminar el texto
Else
Limpiar(c)
End If
If TypeOf c Is ComboBox Then
c.Text = "" ' eliminar el texto
Else
Limpiar(c)
End If
If (TypeOf (c) Is CheckBox) Then
CType(c, CheckBox).Checked = False
Else
Limpiar(c)
End If
If TypeOf c Is DateTimePicker Then
c.Text = Date.Today ' eliminar el texto
Else
Limpiar(c)
End If
Next
End Sub
Private Sub btnVolver_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnVolver.Click
Me.Hide()
MenuPrincipal.Show()
End Sub
Private Sub btnIngresar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnIngresar.Click
Try
ConexionODBC.conecta()
Sql = "SELECT CI from persona where CI='" & txtCI.Text & "'"
comando.Connection = conectar
comando.CommandText = Sql
dr = comando.ExecuteReader()
If dr.HasRows Then
valido = True
Else
valido = False
End If
ConexionODBC.cerrar()
If valido = False Then
ConexionODBC.conecta()
Sql = "INSERT INTO persona VALUES('" & txtCI.Text & "' , '" & txtNombre.Text & "' , '" & txtApellido.Text & "' , '" & txtEmail.Text & "' ) "
comando.Connection = conectar
comando.CommandText = Sql
comando.ExecuteReader()
MsgBox("Ingresado")
Else
MsgBox(" No Ingresado")
End If
Catch ex As Exception
MsgBox("No se pudieron ingresar datos")
End Try
Me.Hide()
MenuPrincipal.Show()
End Sub
Valora esta pregunta


0