Jump to content
Sign in to follow this  
nelgaio

ComboBox, procurar na BD?

Recommended Posts

nelgaio

Boas :D

Eu tenho este código que andei a inventar um pouco :thumbsup:

Mas não está a funcionar, alguém sabe porque?

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim ConnectionString As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" & Application.StartupPath & "\pap.accdb")
        Dim query As String = "SELECT * FROM faltas WHERE ID = @ID_Disciplina"

        Dim command As New OleDbCommand(query, ConnectionString)
        ' Seleccionar os dados APENAS do cliente 3
        If ComboBox1.Text = "Matemática" Then
            command.Parameters.Add("@ID_Disciplina", OleDbType.Integer).Value = 1
        ElseIf ComboBox1.Text = "Português" Then
            command.Parameters.Add("@ID_Disciplina", OleDbType.Integer).Value = 2
        ElseIf ComboBox1.Text = "Inglês" Then
            command.Parameters.Add("@ID_Disciplina", OleDbType.Integer).Value = 3
        ElseIf ComboBox1.Text = "PSI" Then
            command.Parameters.Add("@ID_Disciplina", OleDbType.Integer).Value = 4
        End If

        Dim DataAdapter As New OleDbDataAdapter(command)
        Dim MyData As New DataSet
        DataAdapter.Fill(MyData, "faltas")

        Me.FaltasDataGridView.DataSource = MyData.Tables("faltas")
    End Sub

Share this post


Link to post
Share on other sites
tiagoamaros

Boas nelgaio,

Dá-te algum erro em alguma das linhas??

Ou ao correres o programa ele simplesmente nao faz nada??

Abraço

Share this post


Link to post
Share on other sites

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