none
Melhor método de consulta DB para itens de um grupo? RRS feed

  • Pergunta

  • Bom dia,

    Tenho procurado solucoes para o  VB2010professional neste forum mas não estou conseguindo respostas para filtrar registros de um grupo de registros através de comobobox. Ex: escolhendo uma UF retornar os respectivos municípios daquele estado, tendo uma conexão com MySQL.]

    Qual o método mais adequado para isso

    ?

    sábado, 18 de fevereiro de 2012 12:54

Respostas

  • Private Sub Inserir()
    	Dim Cnn_Command As New OleDbCommand()
    	Dim adapter As New OleDbDataAdapter()
    	Dim conn As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Levi\Documents\Database_Desenvolvimento.accdb")
    
    
    	Try
    		conn.Open()
    		Cnn_Command.Connection = conn
    		Cnn_Command.CommandText = "Select * from Table1 Where ID =@Combobox"
    		Cnn_Command.Parameters.AddWithValue("@Combobox", Me.comboBox1.SelectedItem.ToString())
    		Cnn_Command.CommandType = CommandType.Text
    		adapter.SelectCommand = Cnn_Command
    
    		Dim tb As New DataTable()
    		adapter.Fill(tb)
    		Me.dataGridView1.DataSource = tb
    
    	Catch ex As OleDbException
    		MessageBox.Show(ex.GetBaseException().ToString())
    	Finally
    		conn.Close()
    	End Try
    End Sub

    One word frees us of all the weight and pain of life: that word is love.

    • Marcado como Resposta Boris Wilson segunda-feira, 20 de fevereiro de 2012 19:23
    sábado, 18 de fevereiro de 2012 20:20

Todas as Respostas

  •   private void Pesquizar()
            {

    troca a tua conecao pra mysql

               OleDbCommand Cnn_Command = new OleDbCommand();
                OleDbDataAdapter adapter = new OleDbDataAdapter();
                OleDbConnection conn = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Levi\Documents\Database_Desenvolvimento.accdb");



                     try
                     {
                         conn.Open();
                         Cnn_Command.Connection = conn;
                         Cnn_Command.CommandText = "Select * from Table1 Where ID =@Combobox";    
                         Cnn_Command.Parameters.AddWithValue("@Combobox",this.comboBox1.SelectedItem.ToString());
                         Cnn_Command.CommandType = CommandType.Text;
                         adapter.SelectCommand = Cnn_Command;


                         DataTable tb = new DataTable();
                         adapter.Fill(tb);
                         this.dataGridView1.DataSource = tb;
                     }

                catch (OleDbException ex)
                     {
                    MessageBox.Show(ex.GetBaseException().ToString());
                }
             finally 
                     {conn.Close();
                     }
            }

                               

    One word frees us of all the weight and pain of life: that word is love.

    sábado, 18 de fevereiro de 2012 20:17
  • Private Sub Inserir()
    	Dim Cnn_Command As New OleDbCommand()
    	Dim adapter As New OleDbDataAdapter()
    	Dim conn As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Levi\Documents\Database_Desenvolvimento.accdb")
    
    
    	Try
    		conn.Open()
    		Cnn_Command.Connection = conn
    		Cnn_Command.CommandText = "Select * from Table1 Where ID =@Combobox"
    		Cnn_Command.Parameters.AddWithValue("@Combobox", Me.comboBox1.SelectedItem.ToString())
    		Cnn_Command.CommandType = CommandType.Text
    		adapter.SelectCommand = Cnn_Command
    
    		Dim tb As New DataTable()
    		adapter.Fill(tb)
    		Me.dataGridView1.DataSource = tb
    
    	Catch ex As OleDbException
    		MessageBox.Show(ex.GetBaseException().ToString())
    	Finally
    		conn.Close()
    	End Try
    End Sub

    One word frees us of all the weight and pain of life: that word is love.

    • Marcado como Resposta Boris Wilson segunda-feira, 20 de fevereiro de 2012 19:23
    sábado, 18 de fevereiro de 2012 20:20