locked
Error al Ejecutar el proyecto (falta de operando) RRS feed

  • Pregunta

  • Buenas!!

    estoy empezando a programar en Visual Basic y me aparece un error que no me dice mucho, en la lista de errores no me aparece ninguno pero a la hora de ejecutarlo me aparece, "ERROR DE SINTAXIS FALTA DE OPERANDO DESPUES DEL OPERADOR 'DE' " y cuando le doy aceptar todo funciona bien, me muestra los registros que tengo capturados hasta el momento espero me puedan ayudar a continuación les dejo una imagen y mi codigo, gracias de antemando.

    MI ARCHIVO CONEXION

    Public Class conexion
        Protected cnn As New SqlClient.SqlConnection

        Public idusuario As Integer
        Protected Function conectado()
            Try
                cnn = New SqlConnection("Data Source=AARON-PC\SQLEXPRESS; initial catalog=testventas; Integrated Security=True")
                cnn.Open()
                Return True

            Catch ex As Exception
                MsgBox(ex.Message)
                Return False
            End Try
        End Function

        Protected Function desconectado()
            Try
                If cnn.State = ConnectionState.Open Then
                    cnn.Close()
                    Return True
                Else
                    Return False
                End If
            Catch ex As Exception
                MsgBox(ex.Message)
                Return False
            End Try
        End Function
    End Class

    MI ARCHIVO FCLIENTE

    Public Class fcliente
        Inherits conexion
        Dim cmd As New SqlCommand

        Public Function mostrar() As DataTable

            Try
                conectado()
                cmd = New SqlCommand("mostrar_cliente")
                cmd.CommandType = CommandType.StoredProcedure

                cmd.Connection = cnn

                If cmd.ExecuteNonQuery Then
                    Dim dt As New DataTable
                    Dim da As New SqlDataAdapter(cmd)
                    da.Fill(dt)
                    Return dt
                Else
                    Return Nothing
                End If
            Catch ex As Exception
                MsgBox(ex.Message)
                Return Nothing
            Finally
                desconectado()
            End Try
        End Function

        Public Function insertar(ByVal dts As vcliente) As Boolean
            Try
                conectado()
                cmd = New SqlCommand("insertar_cliente")
                cmd.CommandType = CommandType.StoredProcedure
                cmd.Connection = cnn

                cmd.Parameters.AddWithValue("@nombre", dts.gnombre)
                cmd.Parameters.AddWithValue("@apellidos", dts.gapellidos)
                cmd.Parameters.AddWithValue("@direccion", dts.gdireccion)
                cmd.Parameters.AddWithValue("@telefono", dts.gtelefono)
                cmd.Parameters.AddWithValue("@dni", dts.gdni)

                If cmd.ExecuteNonQuery Then
                    Return True
                Else
                    Return False
                End If

            Catch ex As Exception
                MsgBox(ex.Message)
                Return False
            Finally
                desconectado()

            End Try
        End Function

        Public Function editar(ByVal dts As vcliente) As Boolean
            Try
                conectado()
                cmd = New SqlCommand("editar_cliente")
                cmd.CommandType = CommandType.StoredProcedure
                cmd.Connection = cnn

                cmd.Parameters.AddWithValue("@idcliente", dts.gidcliente)
                cmd.Parameters.AddWithValue("@nombre", dts.gnombre)
                cmd.Parameters.AddWithValue("@apellidos", dts.gapellidos)
                cmd.Parameters.AddWithValue("@direccion", dts.gdireccion)
                cmd.Parameters.AddWithValue("@telefono", dts.gtelefono)
                cmd.Parameters.AddWithValue("@dni", dts.gdni)

                If cmd.ExecuteNonQuery Then
                    Return True
                Else
                    Return False
                End If

            Catch ex As Exception
                MsgBox(ex.Message)
                Return False
            Finally
                desconectado()

            End Try
        End Function

        Public Function eliminar(ByVal dts As vcliente) As Boolean
            Try
                conectado()
                cmd = New SqlCommand("eliminar_cliente")
                cmd.CommandType = CommandType.StoredProcedure
                cmd.Connection = cnn

                cmd.Parameters.Add("@idcliente", SqlDbType.NVarChar, 50).Value = dts.gidcliente
                If cmd.ExecuteNonQuery Then
                    Return True
                Else
                    Return False
                End If
            Catch ex As Exception
                MsgBox(ex.Message)
                Return False
            End Try
        End Function
    End Class

    MI ARCHIVO VCLIENTE

    Public Class vcliente

        Dim idcliente As Integer
        Dim nombre, apellidos, direccion, telefono, dni As String

        'seeter y getter
        Public Property gidcliente
            Get
                Return idcliente
            End Get
            Set(value)
                idcliente = value
            End Set
        End Property

        Public Property gnombre
            Get
                Return nombre
            End Get
            Set(value)
                nombre = value
            End Set
        End Property

        Public Property gapellidos
            Get
                Return apellidos
            End Get
            Set(value)
                apellidos = value
            End Set
        End Property

        Public Property gdireccion
            Get
                Return direccion
            End Get
            Set(value)
                direccion = value
            End Set
        End Property

        Public Property gtelefono
            Get
                Return telefono
            End Get
            Set(value)
                telefono = value
            End Set
        End Property
        Public Property gdni
            Get
                Return dni
            End Get
            Set(value)
                dni = value
            End Set
        End Property

        'constructores

        Public Sub New()

        End Sub

        Public Sub New(ByVal idcliente As Integer, ByVal nombre As String, ByVal apellidos As String, ByVal direccion As String, ByVal telefono As String, ByVal dni As String)
            gidcliente = idcliente
            gnombre = nombre
            gapellidos = apellidos
            gdireccion = direccion
            gtelefono = telefono
            gdni = dni
        End Sub
    End Class

    sábado, 23 de noviembre de 2013 5:51

Respuestas

  • "Aaron Rincon" escribió:

    > ya revise mis procedimientos almacenados y no encuentro
    > ningun error son algo simples aqui te los dejo por si
    > estoy dejando pasar algo

    No encuentro nada extraño en la sintaxis de los procedimientos almacenados que has indicado, pero insisto que el mensaje "ERROR DE SINTAXIS FALTA DE OPERANDO DESPUES DEL OPERADOR 'DE'", que yo sepa no procede de Visual Basic ni de ninguna clase existente en el marco de trabajo de .NET, más bien del motor de base de datos de SQL Server. Pero si dices que los procedimientos almacenados están correctos, y así parece ser por el contenido de tu anterior mensaje, no voy a ser yo el que lo ponga en duda. ;-)

    Aprovecho el mensaje para indicarte cómo tienes que definir tu clase Cliente (no 'fcliente' ni 'vcliente'):

    Imports System.Data.SqlClient Public Class Cliente Private m_idCliente As Integer Private m_nombre, m_apellidos, m_direccion, m_telefono, m_dni As String Private Shared cadenaConexion As String = _ "Data Source=AARON-PC\SQLEXPRESS;Initial Catalog=testventas;Integrated Security=True" 'constructores Public Sub New() End Sub Public Sub New(ByVal idCliente As Integer, ByVal nombre As String, _ ByVal apellidos As String, ByVal direccion As String, _ ByVal telefono As String, ByVal m_dni As String) m_idCliente = idCliente m_nombre = nombre m_apellidos = apellidos m_direccion = direccion m_telefono = telefono m_dni = Dni End Sub Public Property IdCliente As Integer Get Return m_idCliente End Get Set(value As Integer) m_idCliente = value End Set End Property Public Property Nombre As String Get Return m_nombre End Get Set(value As String) m_nombre = value End Set End Property Public Property Apellidos As String Get Return m_apellidos End Get Set(value As String) m_apellidos = value End Set End Property Public Property Direccion As String Get Return m_direccion End Get Set(value As String) m_direccion = value End Set End Property Public Property Telefono As String Get Return m_telefono End Get Set(value As String) m_telefono = value End Set End Property Public Property Dni As String Get Return m_dni End Get Set(value As String) m_dni = value End Set End Property Public Shared Function Mostrar() As DataTable Using cnn As New SqlConnection(cadenaConexion) Dim cmd As SqlCommand = cnn.CreateCommand() cmd.CommandText = "mostrar_cliente" cmd.CommandType = CommandType.StoredProcedure Dim dt As New DataTable() Dim da As New SqlDataAdapter(cmd) da.Fill(dt) Return dt End Using End Function Public Shared Sub Insertar(ByVal dts As Cliente) Using cmd As New SqlCommand() cmd.CommandText = "insertar_cliente" cmd.CommandType = CommandType.StoredProcedure Dim value As Object = If(String.IsNullOrEmpty(dts.Nombre), CObj(DBNull.Value), dts.Nombre) cmd.Parameters.AddWithValue("@nombre", value) value = If(String.IsNullOrEmpty(dts.Apellidos), CObj(DBNull.Value), dts.Apellidos) cmd.Parameters.AddWithValue("@apellidos", value) value = If(String.IsNullOrEmpty(dts.Direccion), CObj(DBNull.Value), dts.Direccion) cmd.Parameters.AddWithValue("@direccion", value) value = If(String.IsNullOrEmpty(dts.Telefono), CObj(DBNull.Value), dts.Telefono) cmd.Parameters.AddWithValue("@telefono", value) value = If(String.IsNullOrEmpty(dts.Dni), CObj(DBNull.Value), dts.Dni) cmd.Parameters.AddWithValue("@dni", value) ExecuteAction(cmd) End Using End Sub

        Public Shared Sub Editar(ByVal dts As Cliente)

            Using cmd As New SqlCommand()
                cmd.CommandText = "editar_cliente"
                cmd.CommandType = CommandType.StoredProcedure
                cmd.Parameters.AddWithValue("@idcliente", dts.IdCliente)

                Dim value As Object = If(String.IsNullOrEmpty(dts.Nombre), CObj(DBNull.Value), dts.Nombre)
                cmd.Parameters.AddWithValue("@nombre", value)

                value = If(String.IsNullOrEmpty(dts.Apellidos), CObj(DBNull.Value), dts.Apellidos)
                cmd.Parameters.AddWithValue("@apellidos", value)

                value = If(String.IsNullOrEmpty(dts.Direccion), CObj(DBNull.Value), dts.Direccion)
                cmd.Parameters.AddWithValue("@direccion", value)

                value = If(String.IsNullOrEmpty(dts.Telefono), CObj(DBNull.Value), dts.Telefono)
                cmd.Parameters.AddWithValue("@telefono", value)

                value = If(String.IsNullOrEmpty(dts.Dni), CObj(DBNull.Value), dts.Dni)
                cmd.Parameters.AddWithValue("@dni", value)

                Dim n As Integer = ExecuteAction(cmd)
                If (n = 0) Then
                    Throw New ArgumentException("No existe el cliente especificado.")
                End If
            End Using

        End Sub

        Public Shared Sub Eliminar(ByVal dts As Cliente)

            Using cmd As New SqlCommand()
                cmd.CommandText = "eliminar_cliente"
                cmd.CommandType = CommandType.StoredProcedure
                'cmd.Parameters.Add("@idcliente", SqlDbType.NVarChar, 50).Value = dts.IdCliente
                cmd.Parameters.AddWithValue("@idcliente", dts.IdCliente)

                Dim n As Integer = ExecuteAction(cmd)
                If (n = 0) Then
                    Throw New ArgumentException("No existe el cliente especificado.")
                End If
            End Using

        End Sub

    Private Shared Function ExecuteAction(cmd As SqlCommand) As Integer If (cmd Is Nothing) Then Return 0 Using cnn As New SqlConnection(cadenaConexion) cmd.Connection = cnn cnn.Open() Return cmd.ExecuteNonQuery() End Using End Function End Class


    Como podrás comprobar, para nada te hace falta una clase llamada 'conexion', ni tampoco una clase llamada 'fcliente', porque en la misma clase Cliente puedes incluir procedimientos compartidos (Shared) para insertar, modificar, eliminar y mostrar los datos, procedimientos estos que tampoco es necesario que devuelvan un valor Boolean ni que se capture en ellos la posible excepción que se pueda producir, ya que ésta se tiene que capturar en el código llamador o cliente.

    Y el código del formulario cliente será algo parecido al siguiente:

    Public Class Form1
    
        Private Sub btnMostrar_Click(sender As Object, e As EventArgs) Handles btnMostrar.Click
    
            Try
                Dim dt As DataTable = Cliente.Mostrar()
                DataGridView1.DataSource = dt
    
            Catch ex As Exception
                MessageBox.Show(ex.Message)
    
            End Try
    
        End Sub
    
        Private Sub btnInsertar_Click(sender As Object, e As EventArgs) Handles btnInsertar.Click
    
            Try
                Dim c As New Cliente()
                c.Nombre = txtNombre.Text.Trim()
                c.Apellidos = txtApellidos.Text.Trim()
                c.Dni = txtDni.Text.Trim()
                c.Direccion = txtDireccion.Text.Trim()
                c.Telefono = txtTelefono.Text.Trim()
                Cliente.Insertar(c)
    
                MessageBox.Show("Se ha añadido el nuevo registro.")
    
            Catch ex As Exception
                MessageBox.Show(ex.Message)
    
            End Try
    
        End Sub
    
        Private Sub btnActualizar_Click(sender As Object, e As EventArgs) Handles btnActualizar.Click
    
            Try
                Dim idCliente As Integer
                Dim bln As Boolean = Integer.TryParse(txtIdCliente.Text.Trim(), idCliente)
    
                If (Not (bln)) Then
                    txtIdCliente.Clear()
                    MessageBox.Show("El identificador del cliente no es válido.")
                    Return
                End If
    
                Dim c As New Cliente()
                c.IdCliente = idCliente
                c.Nombre = txtNombre.Text.Trim()
                c.Apellidos = txtApellidos.Text.Trim()
                c.Dni = txtDni.Text.Trim()
                c.Direccion = txtDireccion.Text.Trim()
                c.Telefono = txtTelefono.Text.Trim()
                Cliente.Editar(c)
    
                MessageBox.Show("Se ha actualizado el registro.")
    
            Catch ex As Exception
                MessageBox.Show(ex.Message)
    
            End Try
    
        End Sub
    
        Private Sub btnEliminar_Click(sender As Object, e As EventArgs) Handles btnEliminar.Click
    
            Try
                Dim idCliente As Integer
                Dim bln As Boolean = Integer.TryParse(txtIdCliente.Text.Trim(), idCliente)
    
                If (Not (bln)) Then
                    txtIdCliente.Clear()
                    MessageBox.Show("El identificador del cliente no es válido.")
                    Return
                End If
    
                Dim c As New Cliente()
                c.IdCliente = idCliente
                Cliente.Eliminar(c)
    
                MessageBox.Show("Se ha eliminado el registro.")
    
            Catch ex As Exception
                MessageBox.Show(ex.Message)
    
            End Try
    
        End Sub
    
    End Class

    Digamos que esta es la manera "certificada" (nótese las comillas dobles) de llamar a los distintos procedimientos existentes en la clase 'Cliente'.

    Si la sintaxis de los distintos procedimientos almacenados es correcta, entiendo que no tienes por qué obtener un mensaje de "ERROR DE SINTAXIS FALTA DE OPERANDO DESPUES DEL OPERADOR 'DE'".


    Enrique Martínez Montejo
            [MS MVP - VB]

    Nota informativa: La información contenida en este mensaje, así como el código fuente incluido en el mismo, se proporciona «COMO ESTÁ», sin garantías de ninguna clase, y no otorga derecho alguno. Usted asume cualquier riesgo al poner en práctica, utilizar o ejecutar lo recomendado o sugerido en el presente mensaje.

    Si esta respuesta le ha resultado útil, recuerde marcarla como satisfactoria.

    Si usas Visual Basic .NET y deseas ser productivo y feliz, se inteligente y activa la instrucción
    Option Strict.


    miércoles, 27 de noviembre de 2013 11:26
    Moderador

Todas las respuestas

  • Revisaste depurarlo paso a paso para ver en que procedimiento te marca dicho error?

    Saludos,
    Recuerda que si las respuestas te ayudan a resolver tus problemas no olvides marcarla como respuesta, ya que otros usuarios pueden tener el mismo problema.
    J. Miguel

    domingo, 24 de noviembre de 2013 6:46
  • "Aaron Rincon" escribió:

    > me aparece un error que no me dice mucho, en la lista
    > de errores no me aparece ninguno pero a la hora de
    > ejecutarlo me aparece, "ERROR DE SINTAXIS FALTA DE
    > OPERANDO DESPUES DEL OPERADOR 'DE' " y cuando le doy
    > aceptar todo funciona bien, me muestra los registros
    > que tengo capturados hasta el momento

    Hola, Aaron:

    Como observo que estás ejecutando procedimientos almacenados existentes en tu base de datos de SQL Server, no me queda más remedio que pensar que ese error de sintaxis se encuentre en algún procedimiento almacenado de los que estás ejecutando, de ahí que en la lista de errores del IDE de Visual Studio no te aparezca ninguno, por tanto, tendrás que revisar la sintaxis del procedimiento almacenado que te arroja el error comentado.

    Por cierto, te hago saber que todos los procedimiento Function deberán devolver un valor, cuyo tipo de dato tiene que estar debidamente definido en la firma del procedimiento.

       Protected Function conectado()

       End Function

    Si tu intención es devolver un valor Boolean (True/False), la firma de la función deberá ser:

       Protected Function conectado() As Boolean
    
       End Function

    Otro tanto de lo mismo sucede con los procedimientos Property, que deberán devolver un tipo de dato adecuado:

         Public Property gidcliente As Integer
             Get
                 Return idcliente
             End Get
             Set(value As Integer)
                 idcliente = value
             End Set
         End Property

    Te funciona porque con total seguridad tendrás desactivada la instrucción Option Strict. Revisa el enlace que aparece en la "coletilla" final de este mensaje.

    Un saludo


    Enrique Martínez
      [MS MVP - VB]

    Nota informativa: La información contenida en este mensaje, así como el código fuente incluido en el mismo, se proporciona «COMO ESTÁ», sin garantías de ninguna clase, y no otorga derecho alguno. Usted asume cualquier riesgo al poner en práctica, utilizar o ejecutar lo recomendado o sugerido en el presente mensaje.

    Si esta respuesta le ha resultado útil, recuerde marcarla como satisfactoria.

    Si usas Visual Basic .NET y deseas ser productivo y feliz, se inteligente y activa la instrucción Option Strict.


    domingo, 24 de noviembre de 2013 7:18
    Moderador
  • Gracias por tomarte el tiempo para responder, ya revise mis procedimientos almacenados y no encuentro ningun error son algo simples aqui te los dejo por si estoy dejando pasar algo

     MOSTRAR CLIENTE

    select * from cliente order by idcliente

    ELIMINAR CLIENTE

    @idcliente integer
    as
    delete from cliente where idcliente=@idcliente 

    MODIFICAR CLIENTE

    @idcliente integer,
    @nombre varchar(50),
    @apellidos varchar(50),
    @direccion varchar(100),
    @telefono varchar(9),
    @dni varchar(8)
    as
    update cliente set nombre=@nombre, apellidos=@apellidos, direccion=@direccion, telefono=@telefono, dni=@dni 
    where idcliente=@idcliente 

    INSERTAR CLIENTE

    @nombre varchar(50),
    @apellidos varchar(50),
    @direccion varchar(100),
    @telefono varchar(10),
    @dni varchar(8)
    as
    insert into cliente(nombre, apellidos, direccion, telefono, dni) values (@nombre,@apellidos, @direccion, @telefono, @dni)

    GRACIAS OTRA VES POR LA AYUDA

    martes, 26 de noviembre de 2013 17:42
  • "Aaron Rincon" escribió:

    > ya revise mis procedimientos almacenados y no encuentro
    > ningun error son algo simples aqui te los dejo por si
    > estoy dejando pasar algo

    No encuentro nada extraño en la sintaxis de los procedimientos almacenados que has indicado, pero insisto que el mensaje "ERROR DE SINTAXIS FALTA DE OPERANDO DESPUES DEL OPERADOR 'DE'", que yo sepa no procede de Visual Basic ni de ninguna clase existente en el marco de trabajo de .NET, más bien del motor de base de datos de SQL Server. Pero si dices que los procedimientos almacenados están correctos, y así parece ser por el contenido de tu anterior mensaje, no voy a ser yo el que lo ponga en duda. ;-)

    Aprovecho el mensaje para indicarte cómo tienes que definir tu clase Cliente (no 'fcliente' ni 'vcliente'):

    Imports System.Data.SqlClient Public Class Cliente Private m_idCliente As Integer Private m_nombre, m_apellidos, m_direccion, m_telefono, m_dni As String Private Shared cadenaConexion As String = _ "Data Source=AARON-PC\SQLEXPRESS;Initial Catalog=testventas;Integrated Security=True" 'constructores Public Sub New() End Sub Public Sub New(ByVal idCliente As Integer, ByVal nombre As String, _ ByVal apellidos As String, ByVal direccion As String, _ ByVal telefono As String, ByVal m_dni As String) m_idCliente = idCliente m_nombre = nombre m_apellidos = apellidos m_direccion = direccion m_telefono = telefono m_dni = Dni End Sub Public Property IdCliente As Integer Get Return m_idCliente End Get Set(value As Integer) m_idCliente = value End Set End Property Public Property Nombre As String Get Return m_nombre End Get Set(value As String) m_nombre = value End Set End Property Public Property Apellidos As String Get Return m_apellidos End Get Set(value As String) m_apellidos = value End Set End Property Public Property Direccion As String Get Return m_direccion End Get Set(value As String) m_direccion = value End Set End Property Public Property Telefono As String Get Return m_telefono End Get Set(value As String) m_telefono = value End Set End Property Public Property Dni As String Get Return m_dni End Get Set(value As String) m_dni = value End Set End Property Public Shared Function Mostrar() As DataTable Using cnn As New SqlConnection(cadenaConexion) Dim cmd As SqlCommand = cnn.CreateCommand() cmd.CommandText = "mostrar_cliente" cmd.CommandType = CommandType.StoredProcedure Dim dt As New DataTable() Dim da As New SqlDataAdapter(cmd) da.Fill(dt) Return dt End Using End Function Public Shared Sub Insertar(ByVal dts As Cliente) Using cmd As New SqlCommand() cmd.CommandText = "insertar_cliente" cmd.CommandType = CommandType.StoredProcedure Dim value As Object = If(String.IsNullOrEmpty(dts.Nombre), CObj(DBNull.Value), dts.Nombre) cmd.Parameters.AddWithValue("@nombre", value) value = If(String.IsNullOrEmpty(dts.Apellidos), CObj(DBNull.Value), dts.Apellidos) cmd.Parameters.AddWithValue("@apellidos", value) value = If(String.IsNullOrEmpty(dts.Direccion), CObj(DBNull.Value), dts.Direccion) cmd.Parameters.AddWithValue("@direccion", value) value = If(String.IsNullOrEmpty(dts.Telefono), CObj(DBNull.Value), dts.Telefono) cmd.Parameters.AddWithValue("@telefono", value) value = If(String.IsNullOrEmpty(dts.Dni), CObj(DBNull.Value), dts.Dni) cmd.Parameters.AddWithValue("@dni", value) ExecuteAction(cmd) End Using End Sub

        Public Shared Sub Editar(ByVal dts As Cliente)

            Using cmd As New SqlCommand()
                cmd.CommandText = "editar_cliente"
                cmd.CommandType = CommandType.StoredProcedure
                cmd.Parameters.AddWithValue("@idcliente", dts.IdCliente)

                Dim value As Object = If(String.IsNullOrEmpty(dts.Nombre), CObj(DBNull.Value), dts.Nombre)
                cmd.Parameters.AddWithValue("@nombre", value)

                value = If(String.IsNullOrEmpty(dts.Apellidos), CObj(DBNull.Value), dts.Apellidos)
                cmd.Parameters.AddWithValue("@apellidos", value)

                value = If(String.IsNullOrEmpty(dts.Direccion), CObj(DBNull.Value), dts.Direccion)
                cmd.Parameters.AddWithValue("@direccion", value)

                value = If(String.IsNullOrEmpty(dts.Telefono), CObj(DBNull.Value), dts.Telefono)
                cmd.Parameters.AddWithValue("@telefono", value)

                value = If(String.IsNullOrEmpty(dts.Dni), CObj(DBNull.Value), dts.Dni)
                cmd.Parameters.AddWithValue("@dni", value)

                Dim n As Integer = ExecuteAction(cmd)
                If (n = 0) Then
                    Throw New ArgumentException("No existe el cliente especificado.")
                End If
            End Using

        End Sub

        Public Shared Sub Eliminar(ByVal dts As Cliente)

            Using cmd As New SqlCommand()
                cmd.CommandText = "eliminar_cliente"
                cmd.CommandType = CommandType.StoredProcedure
                'cmd.Parameters.Add("@idcliente", SqlDbType.NVarChar, 50).Value = dts.IdCliente
                cmd.Parameters.AddWithValue("@idcliente", dts.IdCliente)

                Dim n As Integer = ExecuteAction(cmd)
                If (n = 0) Then
                    Throw New ArgumentException("No existe el cliente especificado.")
                End If
            End Using

        End Sub

    Private Shared Function ExecuteAction(cmd As SqlCommand) As Integer If (cmd Is Nothing) Then Return 0 Using cnn As New SqlConnection(cadenaConexion) cmd.Connection = cnn cnn.Open() Return cmd.ExecuteNonQuery() End Using End Function End Class


    Como podrás comprobar, para nada te hace falta una clase llamada 'conexion', ni tampoco una clase llamada 'fcliente', porque en la misma clase Cliente puedes incluir procedimientos compartidos (Shared) para insertar, modificar, eliminar y mostrar los datos, procedimientos estos que tampoco es necesario que devuelvan un valor Boolean ni que se capture en ellos la posible excepción que se pueda producir, ya que ésta se tiene que capturar en el código llamador o cliente.

    Y el código del formulario cliente será algo parecido al siguiente:

    Public Class Form1
    
        Private Sub btnMostrar_Click(sender As Object, e As EventArgs) Handles btnMostrar.Click
    
            Try
                Dim dt As DataTable = Cliente.Mostrar()
                DataGridView1.DataSource = dt
    
            Catch ex As Exception
                MessageBox.Show(ex.Message)
    
            End Try
    
        End Sub
    
        Private Sub btnInsertar_Click(sender As Object, e As EventArgs) Handles btnInsertar.Click
    
            Try
                Dim c As New Cliente()
                c.Nombre = txtNombre.Text.Trim()
                c.Apellidos = txtApellidos.Text.Trim()
                c.Dni = txtDni.Text.Trim()
                c.Direccion = txtDireccion.Text.Trim()
                c.Telefono = txtTelefono.Text.Trim()
                Cliente.Insertar(c)
    
                MessageBox.Show("Se ha añadido el nuevo registro.")
    
            Catch ex As Exception
                MessageBox.Show(ex.Message)
    
            End Try
    
        End Sub
    
        Private Sub btnActualizar_Click(sender As Object, e As EventArgs) Handles btnActualizar.Click
    
            Try
                Dim idCliente As Integer
                Dim bln As Boolean = Integer.TryParse(txtIdCliente.Text.Trim(), idCliente)
    
                If (Not (bln)) Then
                    txtIdCliente.Clear()
                    MessageBox.Show("El identificador del cliente no es válido.")
                    Return
                End If
    
                Dim c As New Cliente()
                c.IdCliente = idCliente
                c.Nombre = txtNombre.Text.Trim()
                c.Apellidos = txtApellidos.Text.Trim()
                c.Dni = txtDni.Text.Trim()
                c.Direccion = txtDireccion.Text.Trim()
                c.Telefono = txtTelefono.Text.Trim()
                Cliente.Editar(c)
    
                MessageBox.Show("Se ha actualizado el registro.")
    
            Catch ex As Exception
                MessageBox.Show(ex.Message)
    
            End Try
    
        End Sub
    
        Private Sub btnEliminar_Click(sender As Object, e As EventArgs) Handles btnEliminar.Click
    
            Try
                Dim idCliente As Integer
                Dim bln As Boolean = Integer.TryParse(txtIdCliente.Text.Trim(), idCliente)
    
                If (Not (bln)) Then
                    txtIdCliente.Clear()
                    MessageBox.Show("El identificador del cliente no es válido.")
                    Return
                End If
    
                Dim c As New Cliente()
                c.IdCliente = idCliente
                Cliente.Eliminar(c)
    
                MessageBox.Show("Se ha eliminado el registro.")
    
            Catch ex As Exception
                MessageBox.Show(ex.Message)
    
            End Try
    
        End Sub
    
    End Class

    Digamos que esta es la manera "certificada" (nótese las comillas dobles) de llamar a los distintos procedimientos existentes en la clase 'Cliente'.

    Si la sintaxis de los distintos procedimientos almacenados es correcta, entiendo que no tienes por qué obtener un mensaje de "ERROR DE SINTAXIS FALTA DE OPERANDO DESPUES DEL OPERADOR 'DE'".


    Enrique Martínez Montejo
            [MS MVP - VB]

    Nota informativa: La información contenida en este mensaje, así como el código fuente incluido en el mismo, se proporciona «COMO ESTÁ», sin garantías de ninguna clase, y no otorga derecho alguno. Usted asume cualquier riesgo al poner en práctica, utilizar o ejecutar lo recomendado o sugerido en el presente mensaje.

    Si esta respuesta le ha resultado útil, recuerde marcarla como satisfactoria.

    Si usas Visual Basic .NET y deseas ser productivo y feliz, se inteligente y activa la instrucción
    Option Strict.


    miércoles, 27 de noviembre de 2013 11:26
    Moderador
  • muchas gracias por tu ayuda, muy buenos tus consejos gracias 

    SALUDOS

    :D

    miércoles, 27 de noviembre de 2013 22:39