Jump to content
  • Revista PROGRAMAR: Já está disponível a edição #60 da revista programar. Faz já o download aqui!

Sign in to follow this  
susie

duvida inserir dados na bd

Recommended Posts

susie

Sou principiante em vb.net. Estou a tentar inserir valores na BD em SQL server a query ta a funcionar correctamente, mas qd chamo o procedimento inserir, ele gera me uma excepçao coloquei a em comentario, a string de conexao tou a recebe-la de um ficheiro xml. Ponho aqui o codigo a primeira liga me a bd a segunda e entao o inserir

Public Overloads Function Conexao() As DataSet

        'strConexao = "server=NEWPOS2\SSILVA;Trusted_Connection=yes;database=estagio"

        Dim objConexao As New SqlConnection(strConexao)

        Try

            objConexao.Open()

        Catch ex As Exception

            MsgBox(ex.Message)

        End Try

        MessageBox.Show("acesso à base de dados!")

    End Function ' Conexao_bd

    Public Function inserir(str As String)

        '  strConexao = "server=NEWPOS2\SSILVA;Trusted_Connection=yes;database=estagio"

        Dim objConexao As New SqlConnection(strConexao)

        Dim ins As New SqlCommand(str, objConexao)

        'Dim val As Integer

        objConexao.Open()

        Try

            ' ins.EndExecuteNonQuery(str)

            ins.ExecuteNonQuery()

         

        Catch ex As Exception  ' Incorrect syntax near ')'. Unclosed quotation mark after the character string ' '

            MsgBox(ex.Message)

        End Try

        MsgBox("dados inseridos")

        Return str

    End Function

desde ja agradeço a ajuda

 

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  

×

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.