Visual Basic.NET - Error oCmd.ExecuteNonQuery()

 
Vista:

Error oCmd.ExecuteNonQuery()

Publicado por cartman (1 intervención) el 11/11/2007 05:59:46
Hola que tal,estoy haciendo una base de datos la cual requiero que me inserte los datos,me carga bien los datos,la base de datos,pero a la hora de querer eliminar o querer insertar datos me marca este error:

An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in system.data.dll

Aditional information: Error del sistema.

Aqué les dejo mis codigos,espero me puedan ayudar.De antemano gracias por su atencion.

Para borrar:

If txtpz.Text = "" Then
If txtnpz.Text = "" Then
If txtpr.Text = "" Then
MsgBox("contraseña incorrecta")
Else
Dim cadenac As String = "DATA SOURCE =X; INITIAL CATALOG= EMPLEADOS; integrated security=true "
Dim oConn As New SqlConnection(cadenac)
oConn.Open()
Dim consulta As String = "DELETE FROM EMPLEADOS Where id_empleado='" & Me.txtpz.Text & "'"
Dim oCmd As New SqlCommand(consulta, oConn)
oCmd.ExecuteNonQuery()
oConn.Close()
MsgBox("Los datos ya han sido eliminados")
txtpz.Text = ""
End If

Else
Dim cadenac As String = "DATA SOURCE =X ; INITIAL CATALOG= EMPLEADOS; integrated security=true "
Dim oConn As New SqlConnection(cadenac)
oConn.Open()
Dim consulta As String = "DELETE FROM EMPLEADOS Where nom_empleado='" & Me.txtnpz.Text & "'"
Dim oCmd As New SqlCommand(consulta, oConn)
oCmd.ExecuteNonQuery()
oConn.Close()
MsgBox("Los datos ya han sido eliminados")
txtnpz.Text = ""
End If
Else
Dim cadenac As String = "DATA SOURCE =X; INITIAL CATALOG= EMPLEADOS; integrated security=true "
Dim oConn As New SqlConnection(cadenac)
oConn.Open()
Dim consulta As String = "DELETE FROM EMPLEADOS Where apel_empleados='" & Me.txtpr.Text & "'"
Dim oCmd As New SqlCommand(consulta, oConn)
oCmd.ExecuteNonQuery()
oConn.Close()
MsgBox("Los datos ya han sido eliminados")
txtpr.Text = ""
End If

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Para insertar datos:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim cadenac As String = "DATA SOURCE =X ; INITIAL CATALOG= SHG; integrated security=true "
Dim oConn As New SqlConnection(cadenac)
oConn.Open()
Dim consulta As String = "INSERT INTO ID(numero_de_pieza,pieza,precio) values(" & Me.txtpz.Text & ",'" & Me.txtnpz.Text & "','" & Me.txtpr.Text & "')"
Dim oCmd As New SqlCommand(consulta, oConn)
oCmd.ExecuteNonQuery()
oCmd.Connection.Open()
oConn.Close()
MsgBox("Sus datos han sido Almacenados")
txtpz.Text = ""
txtnpz.Text = ""
txtpr.Text = ""
End Sub
End Class
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