Jump to content

Recommended Posts

Posted

Boas Pessoal, estou a usar este código, mas não está a dar se alguém me poder dar uma ajuda seria Fantástico .

Cumps !

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim ConnectionString As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Application.StartupPath & "\BD_PAP.mdb")
        Dim query As String = "UPDATE Professor SET [Nome]=@Nome, [bI]=@BI,[Datnasc]=@Datnasc,[Morada]=@Morada,[Contacto]=@Contacto, [codmodalidade]=@codmodalidade, [turma]=@turma Where [nprofessor]=@nprofessor "

        Dim command As New OleDbCommand(query, ConnectionString)

        command.Parameters.Add("@nprofessor", OleDbType.VarChar).Value = TextBox9.Text
        command.Parameters.Add("@Nome", OleDbType.VarChar).Value = TextBox1.Text
        command.Parameters.Add("@BI", OleDbType.VarChar).Value = TextBox2.Text
        command.Parameters.Add("@Datnasc", OleDbType.Date).Value = TextBox3.Text
        command.Parameters.Add("@Morada", OleDbType.VarChar).Value = TextBox4.Text
        command.Parameters.Add("@Contacto", OleDbType.VarChar).Value = TextBox5.Text
        command.Parameters.Add("@codmodalidade", OleDbType.VarChar).Value = TextBox7.Text
        command.Parameters.Add("@turma", OleDbType.VarChar).Value = TextBox8.Text

        ConnectionString.Open()

        Dim x As Integer = Command.ExecuteNonQuery()

        If x < 1 Then
            MessageBox.Show("Erro ao Alterar Registo", My.Application.Info.Title, MessageBoxButtons.OK, MessageBoxIcon.Error)
        Else
            MessageBox.Show("Registo Alterado com Sucesso!", My.Application.Info.Title, MessageBoxButtons.OK, MessageBoxIcon.Information)
        End If

        ConnectionString.Close()
        command = Nothing
    End Sub
Posted

Antes de mais devias dar nomes as textboxes, assim não dá para entender nada...

Existe algum registo com o campo nprofessor igual ao que está na textbox9?

Pedro Martins

Não respondo a duvidas por PM

Posted

eu sei, mas nunca me habituei muito a essa ideia, sei que é mau para mim e para todos vocês que me tentam ajudar, por isso da minha parte peço desculpa.

Sim, existe.

Posted

Verifica se estás a entrar com a data correta. Poderás estar a entrar com uma data num formato errado ou incompleta.

Para testar tenta substituír

command.Parameters.Add("@Datnasc", OleDbType.Date).Value = TextBox3.Text

por

command.Parameters.Add("@Datnasc", OleDbType.Date).Value = Date

Já agora, está a fazer o Update, esse registo existe? Se não existe deves utilizar o Insert?

Cumprimentos

Posted

Boas

Passa a linha

command.Parameters.Add("@nprofessor", OleDbType.VarChar).Value = TextBox9.Text

para o final dos outros parâmetros

Assim:

command.Parameters.Add("@Nome", OleDbType.VarChar).Value = TextBox1.Text
command.Parameters.Add("@BI", OleDbType.VarChar).Value = TextBox2.Text
command.Parameters.Add("@Datnasc", OleDbType.Date).Value = TextBox3.Text
command.Parameters.Add("@Morada", OleDbType.VarChar).Value = TextBox4.Text
command.Parameters.Add("@Contacto", OleDbType.VarChar).Value = TextBox5.Text
command.Parameters.Add("@codmodalidade", OleDbType.VarChar).Value = TextBox7.Text
command.Parameters.Add("@turma", OleDbType.VarChar).Value = TextBox8.Text
command.Parameters.Add("@nprofessor", OleDbType.VarChar).Value = TextBox9.Text

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.