bueno mi problema es el siguiente... este codigo que hize funciona 100% pero hay un detalle que no me gusta y no cacho como sacarlo.. tengo una clase persona y lo llamo desde mi frmEliminar .
el problema es el siguiente.. yo para eliminar, mi sistema me exige que tenga un txtclave.text y txttipo.text (texbox1) en el formulario.
y todos sabemos que para eliminar un registro no es necesario colocar su clave y tipo , basta con el nombre o rut y listo. pero en mi caso si le saco los txtclave.text y txttipo.text no me corre y me tira errores...


alguien me puede decir donde esta el detalle para poder sacar de mi formulario los textbox
CODIGO DE LA CLASE
Código:
Imports System
Imports System.Collections.Generic
Imports System.Text
Imports System.Data.SqlClient
Imports System.Data
Imports Auditoria_de_impresion
Public Class clasePersona
Public Sub New(ByVal perNombre As String, ByVal perContraseña As String, ByVal perTipo As Integer)
Dim usuNombre As String
Dim usuClave As String
Dim usuTipo As Integer
usuNombre = perNombre
usuClave = perContraseña
usuTipo = perTipo
End Sub
Dim conexion As String = "Data Source=localhost\SQLExpress;Initial Catalog=BDIMPRESION;database = usuario; trusted_connection = yes;Integrated Security = True; User Instance=True"
Public Function eliminarUsuario(ByVal usuario As String, ByVal clave As String, ByVal tipo As Integer) As Boolean
Dim cn As New SqlClient.SqlConnection(conexion)
Dim cmd As New SqlClient.SqlCommand("Delete from usuarios Where perNombre = '" & usuario & "' ", cn)
Dim valor As Integer
Try
If cn.State = ConnectionState.Closed Then
cn.Open()
End If
valor = cmd.ExecuteNonQuery()
MsgBox("Usuario Eliminado del Sistema ", MsgBoxStyle.Information)
Finally
cn.Close()
End Try
Return valor
End Function
CODIGO DEL FORM
Código:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim clasePersona As clasePersona = New clasePersona(txtEliminar.Text, txtclave.Text, txttipo.Text)
clasePersona.eliminarUsuario(txtEliminar.Text, txtclave.Text, txttipo.Text)
'If MsgBox("Desea Eliminar al Usuario", MsgBoxStyle.Question + MsgBoxStyle.YesNo, "Eliminar") = MsgBoxResult.Yes Then
' End If
End Sub