Jump to content
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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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.