首页 > 解决方案 > 我在将数据插入到 postgres 表单 Visual basic.Net 时遇到问题

问题描述

这是我的功能

公共函数 AgregarDempartmento(ByVal ldepartamento 作为 LDepartamento) 作为布尔尝试 conectar() 将 cmd 作为新的 Npgsql.NpgsqlCommand("sp_agregar_departamento;", con)

        cmd.CommandType = CommandType.StoredProcedure


        With cmd.Parameters
            .Add(":puestoP", NpgsqlTypes.NpgsqlDbType.Varchar).DataTypeName = ldepartamento._puesto

            .Add(":departamentoP", NpgsqlTypes.NpgsqlDbType.Varchar).DataTypeName = ldepartamento._departamento




        End With

        If cmd.ExecuteNonQuery Then
            Return True
        Else

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

我这样设置 Public Class LDepartamento Dim iddepartamento As Integer Dim puesto, departamento As String

Public Property _iddepartamento
    Set(value)
        iddepartamento = value
    End Set
    Get
        Return iddepartamento
    End Get
End Property



Public Property _puesto
    Set(value)
        puesto = value
    End Set
    Get
        Return puesto
    End Get
End Property
Public Property _departamento
    Set(value)
        departamento = value
    End Set
    Get
        Return departamento
    End Get
End Property

结束类

这就是我从表单中插入的方式

Private Sub Agregar_Click(sender As Object, e As EventArgs) 处理 Agregar.Click

    valores._puesto = txtpuesto.Text
    valores._departamento = txtdepartamento.Text
    If funciones.AgregarDempartmento(valores) Then
            MsgBox("Departamento Agregada Correctamente", MsgBoxStyle.Information, "Registro de Departamento")

            Me.Close()

        Else
            MsgBox("Departamento No Agregada Correctamente", MsgBoxStyle.Exclamation, "Registro de Departamento")
        End If



    MsgBox("Ingrese un departamento Correcta porfavor", MsgBoxStyle.Exclamation, "Registro de Departamento")

End Sub

标签: postgresqlvisual-studio-2010insert

解决方案


推荐阅读