los datos que ingreso a mysql desde visual basic se registran como null
Publicado por sofia (1 intervención) el 24/07/2017 16:18:54
Hola, tengo un problema con mysql y visual basic. Cuando ingreso los datos (nombre, apellido, telefono, direccion y sucursal) en visual basic en mysql aparecen nulos, solamente queda registrado un id pq es AI.
Les paso mi codigo
esta es la clase para introducir datos
LUEGO TENGO UNA CLASE CON LOS DATOS
Y EN EL FORM LO QUE HAGO ES LO SIGUIENTE
He probado cambiar de referencia ya que un compañero lo hizo y le funciono, pero eso no me resolvió el problema. No entiendo por qué no me registra los datos en la base
Les paso mi codigo
esta es la clase para introducir datos
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
Imports MySql.Data
Imports MySql.Data.Types
Imports MySql.Data.MySqlClient
Public Class claseintroducirdatos
Private _adaptador As New MySqlDataAdapter
Public Function insertarDatos(ByVal datos As clasedatos) As Boolean
Dim estado As Boolean = True
Try
conexionGlobal()
_adaptador.InsertCommand = New MySqlCommand("INSERT INTO empleado (nombreE, apellidoE, telefonoE, direccionE, sucursalE) VALUES (@nombreE, @apellidoE, @telefonoE, @direccionE, @sucursalE)", _conexion)
_adaptador.InsertCommand.Parameters.Add("@nombreE", MySqlDbType.VarChar, 45).Value = datos.nombreE
_adaptador.InsertCommand.Parameters.Add("@apellidoE", MySqlDbType.VarChar, 45).Value = datos.apellidoE
_adaptador.InsertCommand.Parameters.Add("@telefonoE", MySqlDbType.Int32, 11).Value = datos.telefonoE
_adaptador.InsertCommand.Parameters.Add("@direccionE", MySqlDbType.VarChar, 45).Value = datos.sucursalE
_adaptador.InsertCommand.Parameters.Add("@sucursalE", MySqlDbType.VarChar, 45).Value = datos.sucursalE
_conexion.Open()
_adaptador.InsertCommand.Connection = _conexion
_adaptador.InsertCommand.ExecuteNonQuery()
Catch ex As Exception
MsgBox(ex.Message)
estado = False
Finally
Cerrar()
End Try
Return estado
End Function
LUEGO TENGO UNA CLASE CON LOS DATOS
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
Public Class clasedatos
Private _idEMPLEADO As Integer
Private _nombreE As String
Private _apellidoE As String
Private _telefonoE As Integer
Private _direccionE As String
Private _sucursalE As String
Public Property idEMPLEADO() As Integer
Get
Return _idEMPLEADO
End Get
Set(ByVal value As Integer)
_idEMPLEADO = value
End Set
End Property
Public Property nombreE() As String
Get
Return _nombreE
End Get
Set(ByVal value As String)
_nombreE = value
End Set
End Property
Public Property apellidoE() As String
Get
Return _apellidoE
End Get
Set(ByVal value As String)
_apellidoE = value
End Set
End Property
Public Property telefonoE() As Integer
Get
Return _telefonoE
End Get
Set(ByVal value As Integer)
_telefonoE = value
End Set
End Property
Public Property direccionE() As String
Get
Return _direccionE
End Get
Set(ByVal value As String)
_direccionE = value
End Set
End Property
Public Property sucursalE() As String
Get
Return _sucursalE
End Get
Set(ByVal value As String)
_sucursalE = value
End Set
End Property
End Class
Y EN EL FORM LO QUE HAGO ES LO SIGUIENTE
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles guardar.Click
Dim conexion As New claseintroducirdatos
Dim datos As New clasedatos
' _dtsdatos.Reset()
datos.nombreE = TextBox2.Text
datos.apellidoE = TextBox3.Text
datos.telefonoE = TextBox4.Text
datos.direccionE = TextBox5.Text
datos.sucursalE = TextBox6.Text
If conexion.insertarDatos(datos) Then
MsgBox("Datos guardados")
_dtsdatos.Reset()
Else
MsgBox("Datos no guardados")
End If
End Sub
He probado cambiar de referencia ya que un compañero lo hizo y le funciono, pero eso no me resolvió el problema. No entiendo por qué no me registra los datos en la base
Valora esta pregunta


0