ExecuteNonQuery() Overflow (Desbordamiento)
Publicado por xve (100 intervenciones) el 25/11/2015 22:10:04
Codigo del Boton agregar
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
Private Sub btnagregar_Click(sender As System.Object, e As System.EventArgs) Handles btnagregar.Click
Try
If (Me.txtmatricula.Text = "") Then
MsgBox("El campo matricula no puede estar vació", MsgBoxStyle.Critical, "Atención")
Me.txtmatricula.Select()
ElseIf (Me.txtnombre.Text = "") Then
MsgBox("El campo nombre no puede estar vació", MsgBoxStyle.Critical, "Atención")
Me.txtnombre.Select()
ElseIf (Me.txtapellido.Text = "") Then
MsgBox("El campo apellido no puede estar vació", MsgBoxStyle.Critical, "Atención")
Me.txtapellido.Select()
ElseIf (Me.txttel.Text = "") Then
MsgBox("El campo telefono no puede estar vació", MsgBoxStyle.Critical, "Atención")
Me.txttel.Select()
Else
Dim matricula As Long
Dim nombre As String = ""
Dim apellido As String = ""
Dim direccion As String = ""
Dim correo As String = ""
Dim telefono As String = ""
Dim carrera As String = ""
matricula = Long.Parse(Me.txtmatricula.Text)
nombre = Me.txtnombre.Text
apellido = Me.txtapellido.Text
direccion = Me.txtdireccion.Text
correo = Me.txtcorreo.Text
telefono = Me.txttel.Text
carrera = Me.txtcarrera.Text
cmd.CommandType = CommandType.Text
cmd.Connection = conn
sql = "INSERT INTO ALUMNOS (NOMBRE, APELLIDOS, DIRECCION, CORREO, TELEFONO, MATRICULA, CARRERA)"
sql += "VALUES ('" & nombre & "','" & apellido & "','" & direccion & "','" & correo & "','" & telefono & "','" & matricula & "','" & carrera & "')"
Try
cmd.CommandText = sql
cmd.ExecuteNonQuery() //<<< Aqui me indica que esta el error
MsgBox("Registro Insertado Correctamente")
Me.txtmatricula.Text = ""
Me.txtnombre.Text = ""
Me.txtapellido.Text = ""
Me.txtdireccion.Text = ""
Me.txtcorreo.Text = ""
Me.txttel.Text = ""
Me.txtcarrera.Text = ""
Catch ex As Exception
If ex.ToString.Contains("valores duplicados") Then
MsgBox("El registro ya existe en la base de datos")
Else
MsgBox(ex.ToString)
End If
End Try
End If
Catch ex As Exception
If ex.ToString.Contains("no tiene el formato") Then
MsgBox("Ingrese solo números en matricula")
Me.txtmatricula.Focus()
Else
MsgBox("Ocurrio un error : " & ex.ToString)
End If
End Try
End Sub
//Modulo de Funciones
Module funciones
'conexión
Public conn As New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=bdsistemauat.accdb;Persist Security Info=False")
Public cmd As New OleDb.OleDbCommand
Public dr As OleDb.OleDbDataReader
Public sql As String = ""
Public Sub consultarPersona(ByRef identificacion As String)
cmd.Connection = conn
cmd.CommandType = CommandType.Text
cmd.CommandText = "SELECT NOMBRE, APELLIDOS, DIRECCION, CORREO, TELEFONO, CARRERA FROM ALUMNOS WHERE MATRICULA=" + identificacion
Try
dr = cmd.ExecuteReader()
Catch ex As Exception
If ex.ToString.Contains("valores para algunos de los parámetros requeridos") Then
MsgBox("Ingrese valores númericos en matricula")
Else
MsgBox("Error: " + ex.ToString)
End If
End Try
End Sub
Public Sub conectarse()
Try
conn.Open()
MsgBox("Conexion exitosa")
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
Public Sub consultar(ByRef matricula As Long)
cmd.Connection = conn
cmd.CommandType = CommandType.Text
If matricula <> "" Then
cmd.CommandText = "SELECT NOMBRE, APELLIDO, DIRECCION, CORREO, TELEFONO, CARRERA FROM WHERE ALUMNOS WHERE MATRICULA=" + matricula
Else
cmd.CommandText = "SELECT NOMBRE, APELLIDO, DIRECCION, CORREO, TELEFONO, CARRERA FROM WHERE ALUMNOS "
End If
Try
dr = cmd.ExecuteReader()
If dr.HasRows Then
While dr.Read()
MsgBox(dr(0).ToString + " " + dr(1).ToString + " " + dr(2).ToString + " " + dr(3).ToString + " " + dr(4).ToString + " " + +dr(5).ToString + " " + +dr(6).ToString + " ")
End While
Else
MsgBox("No existen registros para la consulta")
End If
dr.Close()
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
End Module
Valora esta pregunta


0