Usuario
codificacion para guardar de vb 2010 a acces

Pregunta
-
este es el error
CMD.ExecuteNonQuery() No coinciden los tipos de datos en la expresión de criterios.
Imports System.Data.OleDb
Public Class Form3
Dim N As Integer = 0
Dim CN As New OleDb.OleDbConnection("PROVIDER=MICROSOFT.ACE.OLEDB.12.0;Data Source=I:\Nueva carpeta\pablitop\pablitop\DOBE1.accdb")
Sub MOSTRAR()
Dim DA As New OleDb.OleDbDataAdapter("SELECT * FROM ESTUDIANTES", CN)
Dim DS As New DataSet
DA.Fill(DS, "ESTUDIANTES")
DataGridView1.DataSource = DS.Tables("ESTUDIANTES")
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
Me.Close()
End Sub
Private Sub Form3_Load_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
MOSTRAR()
BLOQUEAR()
End Sub
Sub LIMPIAR()
TextBox17.Clear()
TextBox16.Clear()
TextBox15.Clear()
TextBox14.Clear()
TextBox5.Clear()
TextBox6.Clear()
TextBox7.Clear()
TextBox8.Clear()
TextBox9.Clear()
TextBox10.Clear()
TextBox11.Clear()
TextBox12.Clear()
TextBox13.Clear()
ComboBox1.Text = ""
End Sub
Sub BLOQUEAR()
Button1.Enabled = True
Button2.Enabled = False
Button3.Enabled = True
Button4.Enabled = True
Button10.Enabled = False
End Sub
Sub DESBLOQUEAR()
Button1.Enabled = False
Button2.Enabled = True
Button3.Enabled = False
Button4.Enabled = False
Button10.Enabled = False
End Sub
Sub NUEVO()
Dim CMD As New OleDb.OleDbCommand("INSERT INTO ESTUDIANTES VALUES('" & ComboBox1.Text & "','" & TextBox16.Text & "','" & TextBox17.Text & "','" & TextBox15.Text & "','" & TextBox14.Text & "','" & TextBox5.Text & "','" & TextBox6.Text & "','" & TextBox7.Text & "','" & TextBox8.Text & "','" & TextBox9.Text & "','" & TextBox10.Text & "','" & TextBox11.Text & "','" & TextBox12.Text & "','" & TextBox13.Text & "')", CN)
CN.Open()
CMD.ExecuteNonQuery()
CN.Close()
MOSTRAR()
MsgBox("REGISTRO AGREGADO")
End Sub
Sub MODIFICAR()
Dim CMD As New OleDb.OleDbCommand("UPDATE ESTUDIANTES SET Id ESTUDIANTES='" & ComboBox1.Text & "'NOMBRE='" & TextBox16.Text & "',APELLIDO='" & TextBox17.Text & "',NºCEDULA='" & TextBox15.Text & "',NOMBRE DEL REPRESENTANTE='" & TextBox14.Text & "',ESTADO CIVIL='" & TextBox5.Text & "',EDAD='" & TextBox6.Text & "',LUGAR DE NACIMIENTO='" & TextBox7.Text & "',ENTREVISTA='" & TextBox8.Text & "',FECHA DE ENTREVISTA='" & TextBox9.Text & "',MOTIVO DE ENTREVISTA='" & TextBox10.Text & "',HORA DE ENTREVISTA='" & TextBox11.Text & "',RESOLUCION DE ENTREVISTA='" & TextBox12.Text & "',TRABAJA='" & TextBox13.Text & "' WHERE Id ESTUDIANTE='" & ComboBox1.Text & "'", CN)
CN.Open()
CMD.ExecuteNonQuery()
CN.Close()
MOSTRAR()
MsgBox("REGISTRO ACTUALIZADO")
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
DESBLOQUEAR()
LIMPIAR()
N = 1
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If N = 1 Then
NUEVO()
ElseIf N = 2 Then
MODIFICAR()
End If
BLOQUEAR()
LIMPIAR()
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
DESBLOQUEAR()
N = 2
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
End Sub
Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click
BLOQUEAR()
LIMPIAR()
End Sub
End Class
Todas las respuestas
-
lo primero que puedo decirte con solo mirar el codigo, es que sino suas parametero no esperes que funcione de forma correcta, eso de concatener los valores en un string no esta bien
tendria que ser algo como
Dim query As String = "INSERT INTO ESTUDIANTES (nombrcampo1, nombrecampo2, ....) VALUES (@param1, @param2, ...)" Dim CMD As New OleDb.OleDbCommand(, CN) CMD.Parameters.AddwithValue("@param1", ComboBox1.Text) CMD.Parameters.AddwithValue("@param1", TextBox16.Text) . . CN.Open() CMD.ExecuteNonQuery()
- define los nombres de los campos
- usa parametros
aconsejaria que aplique estos cambios en tu codigo
saludos
Leandro Tuttini
Blog
Buenos Aires
Argentina- Editado Leandro TuttiniMVP domingo, 17 de marzo de 2013 3:19
-
-
- Editado Leandro TuttiniMVP domingo, 17 de marzo de 2013 3:20