Inês Rocha 0 Posted February 25, 2020 Report Share Posted February 25, 2020 (edited) ola estou a fazer um programa de gestão de uma loja de bricolage em visual basic no visual studio 2019 e nao estou a conseguir quando o funcionário procure um id de um produto com uma ComboBox e ele preencha os outros campos como nome categoria subcategoria.... dá-me um erro "data type mismatch in criteria expression" abaixo mando o código e estou a utilizar o Access com base de dados. Imports System.Data Imports System.Data.OleDb Public Class Form1 Private Sub PictureBox2_Click(sender As Object, e As EventArgs) Handles PictureBox2.Click Me.WindowState = FormWindowState.Minimized End Sub Private Sub PictureBox1_Click(sender As Object, e As EventArgs) Handles PictureBox1.Click End End Sub Private Sub btn_sair_Click(sender As Object, e As EventArgs) Handles btn_sair.Click 'Me.Hide() 'Login.Show() End Sub Private Sub btn_regis_Click(sender As Object, e As EventArgs) Handles btn_regis.Click 'adminregis.Show() 'Me.Hide() End Sub Private Sub btn_func_Click(sender As Object, e As EventArgs) Handles btn_func.Click 'adminfunc.Show() 'Me.Hide() End Sub Private Sub PPreenchaComboBox() Using con As OleDbConnection = GetConnection() Try con.Open() Dim slq As String = "SELECT ID_Artigo FROM Artigos" Dim cmd As OleDbCommand = New OleDbCommand(slq, con) Dim da As OleDbDataAdapter = New OleDbDataAdapter(cmd) Dim dt As DataTable = New DataTable da.Fill(dt) txt_ID.DisplayMember = "ID_Artigo" txt_ID.DataSource = dt Catch ex As Exception Finally con.Close() End Try End Using End Sub Private Sub adminart_Load(sender As Object, e As EventArgs) Handles MyBase.Load PPreenchaComboBox() End Sub Private Sub PLerDados() Dim dr As OleDbDataReader Using con As OleDbConnection = GetConnection() Try con.Open() Dim sql As String = "SELECT Nome_Artigo, Stock_Artigo, Preco_Artigo, ID_Categoria, ID_Sub_Categoria FROM Artigos Where ID_Artigo='" & txt_ID.Text & "'" Dim cmd As OleDbCommand = New OleDbCommand(sql, con) dr = cmd.ExecuteReader(CommandBehavior.SingleRow) If dr.HasRows Then dr.Read() txt_nome.Text = dr.Item("Nome_Artigo") txt_Stock.Text = dr.Item("Stock_Artigo") txt_preco.Text = dr.Item("Preco_Artigo") txt_C.Text = dr.Item("ID_Categoria") txt_SC.Text = dr.Item("ID_Sub_Categoria") End If Catch ex As Exception MsgBox(ex.Message) Finally con.Close() End Try End Using End Sub Private Sub txt_ID_SelectedIndexChanged(sender As Object, e As EventArgs) Handles txt_ID.SelectedIndexChanged PLerDados() End Sub End Class Edited February 25, 2020 by Inês Rocha Inês Rocha Link to post Share on other sites
M6 150 Posted February 28, 2020 Report Share Posted February 28, 2020 Pela descrição do erro, diria que estás a tentar usar uma string em vez de um inteiro (ou algo semelhante) na tua pesquisa. 10 REM Generation 48K! 20 INPUT "URL:", A$ 30 IF A$(1 TO 4) = "HTTP" THEN PRINT "400 Bad Request": GOTO 50 40 PRINT "404 Not Found" 50 PRINT "./M6 @ Portugal a Programar." Link to post Share on other sites
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now