Jump to content

Recommended Posts

Posted

Olá bom dia tenho um problema com o meu insert dá-me erro na sintaxe INSERT INTO.

Alguém me poderá ajudar?

O meu código é:

Imports System.Data
Imports System.Data.OleDb
Public Class registar_novo_membro

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Const constr As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\GPSI\Documents\mydb.accdb"
        Dim mydb As New OleDbConnection(constr)
        mydb.Open()

        MsgBox("State: " & mydb.State.ToString(),
        MsgBoxStyle.Information)

        If txtpassregis.Text.Length < 6 And txtconfpassregis.Text.Length < 6 Then
            MessageBox.Show("A sua password deve conter 6 ou mais carateres!")
            txtpassregis.Clear()
            txtconfpassregis.Clear()

        ElseIf txtpassregis.Text <> txtconfpassregis.Text Then
            MessageBox.Show("As senhas têem que ser iguais!")
            txtpassregis.Clear()
            txtconfpassregis.Clear()
        Else

            Dim a, b, c, varsql As String

            a = txtnomeregis.Text
            b = TextBox1.Text
            c = txtpassregis.Text

            varsql = "Insert into registo(nome_completo, username, password)"  "values ('" & txtnomeregis.Text & "','" & TextBox1.Text & "','" & txtpassregis & "')"
            Dim cmd As New OleDbCommand(varsql, mydb)

            cmd.ExecuteScalar()
            MsgBox("Registo introduzido com sucesso!")
            Me.Hide()
            mydb.Close()
        End If

        Login.ShowDialog()
    End Sub

EDIT: GeSHi adicionado

Posted

Boas

Complementando com o que o @Caça disse

1º Falta-te um .Text no txtpassregis

2º Não feches as aspas entre o nome dos campos da tabela e a instrução values

3º Mete o nome dos campos entre parênteses rectos []

Assim:

varsql = "Insert into registo ([nome_completo], [username], [password]) values ('" & txtnomeregis.Text & "','" & TextBox1.Text & "','" & txtpassregis.Text & "')"

E como o Caça disse, utiliza o ExecuteNonQuery

A informática chegou para resolver problemas que antes não existiam

Quem ri por último é porque está conectado a 52 Kbs.

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
×
×
  • 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.