Jump to content

Recommended Posts

Posted (edited)

Boas,

sou novo neste forum j+a visitei algumas veses e gostei das respostas propostas por isso istou aqui a relatar o meu erro.

Quando faço debug no visual basic 10 (express) apaece-me o seguinte err: "Data type mismatch in criteria expression.", se me podessem corrigir aradecia.

Dim ConnectionString As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" & Application.StartupPath & "\Database3.accdb")

Dim query As String = "INSERT INTO Registos([Nome], [Apelido], , [Password], [DataNascimento], [DataRegisto]) VALUES (@Nome, @Apelido, @Email, @Password, @DataNascimento, @DataRegisto)"

Dim command As New OleDbCommand(query, ConnectionString)

command.Parameters.Add("@Nome", OleDbType.VarChar).Value = NomeTextBox.Text

command.Parameters.Add("@Apelido", OleDbType.VarChar).Value = ApelidoTextBox.Text

If RadioBtnMasculino.Checked = True Then

command.Parameters.Add("@Masculino", OleDbType.VarChar).Value = "Masculino"

Else

command.Parameters.Add("@Feminino", OleDbType.VarChar).Value = "Feminino"

End If

command.Parameters.Add("@Email", OleDbType.VarChar).Value = EmailTextBox.Text

command.Parameters.Add("@Password", OleDbType.VarChar).Value = PasswordTextBox.Text

command.Parameters.Add("@DataNascimento", OleDbType.VarChar).Value = DataNascimento.SelectionRange.Start.Date.ToShortDateString()

command.Parameters.Add("@DataRegisto", OleDbType.VarChar).Value = Date.Today

ConnectionString.Open()

Dim x As Integer = command.ExecuteNonQuery() ->ERRO

If x < 1 Then

MessageBox.Show("Erro ao inserir", My.Application.Info.Title, MessageBoxButtons.OK, MessageBoxIcon.Error)

Else

MessageBox.Show("Registo inserido com sucesso!", My.Application.Info.Title, MessageBoxButtons.OK, MessageBoxIcon.Information)

End If

ConnectionString.Close()

command = Nothing

Edited by Mortalmdsl
Posted

Muito obrigado consegui resolver o erro.

Logo depois surgiu outro mas consegui-o corregir, nao tinha implementado o masculino e feminino..

Neste momento consigo gravar a base de dados, mas se esperar uns 10 minutos ela volta para o ID=1... Este e agora o meu button de "Registo"(adiiona dados a base de dados),

Dim ConnectionString As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" & Application.StartupPath & "\Database3.accdb")

Dim query As String = "INSERT INTO Registos([Nome], [Apelido], [sexo], , [Password], [DataNascimento], [DataRegisto]) VALUES (@Nome, @Apelido, @Sexo, @Email, @Password, @DataNascimento, @DataRegisto)"

Dim command As New OleDbCommand(query, ConnectionString)

command.Parameters.Add("@Nome", OleDbType.VarChar).Value = NomeTextBox.Text

command.Parameters.Add("@Apelido", OleDbType.VarChar).Value = ApelidoTextBox.Text

If RadioBtnMasculino.Checked = True Then

command.Parameters.Add("@Sexo", OleDbType.VarChar).Value = "Masculino"

Else

command.Parameters.Add("@Sexo", OleDbType.VarChar).Value = "Feminino"

End If

command.Parameters.Add("@Email", OleDbType.VarChar).Value = EmailTextBox.Text

command.Parameters.Add("@Password", OleDbType.VarChar).Value = PasswordTextBox.Text

command.Parameters.Add("@DataNascimento", OleDbType.Date).Value = txtDataNascimento.Text

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

ConnectionString.Open()

Dim x As Integer = command.ExecuteNonQuery()

If x < 1 Then

MessageBox.Show("Erro ao inserir", My.Application.Info.Title, MessageBoxButtons.OK, MessageBoxIcon.Error)

Else

MessageBox.Show("Registo inserido com sucesso!", My.Application.Info.Title, MessageBoxButtons.OK, MessageBoxIcon.Information)

End If

ConnectionString.Close()

command = Nothing

Posted

Se o ID volta a um, duvido que seja do teu programa (se removesse registos, o ID continuava).

Que sistema operativo estás a usar? Não estás a repor a base de dados?

Algo semelhante acontecia com o Shadow Copy do Windows.

Posted

Tenta fazer isto:

- adiciona registos pela tua aplicação

- entras com o access e fazes alterações (se possivel em alguma tabela que a tua aplicação nao mexa)

- esperas 10 minutos

- entras na aplicação e inseres registos

- verifica se os registos iniciais desapareceram e se a alteração que fizeste directamente no access tambem desapareceu

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.