Jump to content
Sign in to follow this  
evyrondon

Adicionar dados no B.D. com NPGSQL

Recommended Posts

evyrondon

Ola, esto com problemas na alimentacao do banco de dados, quando vou para tela de cadastro, aparece uma janela com o erro 42 601 syntax error near ";". ajudem por fa

Imports Npgsql
Public Class FormularioLocadora
    Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rdoJuridica.CheckedChanged
        lblCPF.Text = "CNPJ"
        txtData.Visible = False
        lblData.Visible = False
    End Sub
    Private Sub RadioButton2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rdoFisica.CheckedChanged
        lblCPF.Text = "CPF"
        txtData.Visible = True
        lblData.Visible = True
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Me.Close()
    End Sub

    Private mDataSet As DataSet

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim ConexaoPG As String = "Server=localhost;Port=5432;User Id=postgres;Password=jk0011;Database=locar Imoveis;Protocol=3;SSL=false; Pooling=true;MinPoolSize=1;MaxPoolSize=20;Encoding=UNICODE;Timeout=15;SslMode=Disable;"

        Dim conn As Npgsql.NpgsqlConnection = Nothing

        Try
            conn = New Npgsql.NpgsqlConnection(ConexaoPG)
            conn.Open()

            Dim SQL As String = "INSERT INTO locadora(codlocadora, nomelocadora, cpf, email, telefone, endlocadora) VALUES (NEXTVAL(NEXTVAL('seq_locadora'),'" & txtnome.Text & "','" & txtCPF.Text & "','" & txtEmail.Text & "','" & txtTelRes.Text & "','" & txtEndereco.Text & "');"

            Dim da As Npgsql.NpgsqlDataAdapter = New Npgsql.NpgsqlDataAdapter(SQL, conn)

            'Instacia um DataSet
            Dim ds As DataSet = New DataSet()

            'Preenche o DataAdapter
            da.Fill(ds, "locatara")

            'Atribiu um Datas

            'aki vai mostra mensagem de erro causo houver
        Catch ex As Exception
            MsgBox(ex.Message)

        Finally
                'se conexao foi estabelecida entao
                If conn.State = ConnectionState.Open Then
                    'fecha a conexao
                    conn.Close()
                End If
                End
        End Try



    End Sub
End Class

Share this post


Link to post
Share on other sites
psantos10

Ola, esto com problemas na alimentacao do banco de dados, quando vou para tela de cadastro, aparece uma janela com o erro 42 601 syntax error near ";". ajudem por fa

Imports Npgsql
Public Class FormularioLocadora
    Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rdoJuridica.CheckedChanged
        lblCPF.Text = "CNPJ"
        txtData.Visible = False
        lblData.Visible = False
    End Sub
    Private Sub RadioButton2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rdoFisica.CheckedChanged
        lblCPF.Text = "CPF"
        txtData.Visible = True
        lblData.Visible = True
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Me.Close()
    End Sub

    Private mDataSet As DataSet

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim ConexaoPG As String = "Server=localhost;Port=5432;User Id=postgres;Password=jk0011;Database=locar Imoveis;Protocol=3;SSL=false; Pooling=true;MinPoolSize=1;MaxPoolSize=20;Encoding=UNICODE;Timeout=15;SslMode=Disable;"

        Dim conn As Npgsql.NpgsqlConnection = Nothing

        Try
            conn = New Npgsql.NpgsqlConnection(ConexaoPG)
            conn.Open()

            Dim SQL As String = "INSERT INTO locadora(codlocadora, nomelocadora, cpf, email, telefone, endlocadora) VALUES (NEXTVAL(NEXTVAL('seq_locadora'),'" & txtnome.Text & "','" & txtCPF.Text & "','" & txtEmail.Text & "','" & txtTelRes.Text & "','" & txtEndereco.Text & "');"

            Dim da As Npgsql.NpgsqlDataAdapter = New Npgsql.NpgsqlDataAdapter(SQL, conn)

            'Instacia um DataSet
            Dim ds As DataSet = New DataSet()

            'Preenche o DataAdapter
            da.Fill(ds, "locatara")

            'Atribiu um Datas

            'aki vai mostra mensagem de erro causo houver
        Catch ex As Exception
            MsgBox(ex.Message)

        Finally
                'se conexao foi estabelecida entao
                If conn.State = ConnectionState.Open Then
                    'fecha a conexao
                    conn.Close()
                End If
                End
        End Try



    End Sub
End Class

comece por alterar esta linha:

   Dim SQL As String = "INSERT INTO locadora(codlocadora, nomelocadora, cpf, email, telefone, endlocadora) VALUES (NEXTVAL(NEXTVAL('seq_locadora'),'" & txtnome.Text & "','" & txtCPF.Text & "','" & txtEmail.Text & "','" & txtTelRes.Text & "','" & txtEndereco.Text & "');"

para

   Dim SQL As String = "INSERT INTO locadora(codlocadora, nomelocadora, cpf, email, telefone, endlocadora) VALUES (NEXTVAL(NEXTVAL('seq_locadora'),'" & txtnome.Text & "','" & txtCPF.Text & "','" & txtEmail.Text & "','" & txtTelRes.Text & "','" & txtEndereco.Text & "')"

cumps

PS


-------Assinatura?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.