Query of two tables VS + Access

Asked

Viewed 22 times

1

I need to link two tables in the same query, but it hasn’t worked very well. I created this code:

try
    {
            String StringCon = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\02_Semestre\PI\00_Arquivos\01_Programação\tblContacts.mdb";
            OleDbConnection conn = new OleDbConnection(StringCon);
            conn.Open();

            string query = "SELECT Campeonato.Nomecamp, Jogadores.Nome, Jogadores.Sobrenome AS Expr1, Rodadas.Nome AS Expr2 FROM((Rodadas INNER JOIN Campeonato ON Rodadas.Campeonato = Campeonato.Nomecamp) INNER JOIN Jogadores ON Rodadas.Nome = Jogadores.Nome AND Rodadas.Sobrenome = Jogadores.Sobrenome)";

            OleDbCommand cmd = new OleDbCommand(query, conn);
            cmd.Parameters.AddWithValue("@nome", boxnome1.Text);
            cmd.Parameters.AddWithValue("@sobrenome", boxsobrenome1.Text);
            cmd.Parameters.AddWithValue("@campeonato", boxcam1.Text);

            OleDbDataReader dr = cmd.ExecuteReader();

            if (dr.Read())
            {
                MessageBox.Show("Jogador Cadastrado no sistema \n\n Bom Jogo!!!");
                btnInsert.Visible = true;
            }
            else
            {
                MessageBox.Show("Jogador não cadastrado.");
            }
            }
        catch (Exception erro)
        {
            MessageBox.Show(erro.Message);
        }

The problem is that there is no error, but you can’t find what I need either. I think my string is totally wrong. How to perform this search after typing in 3 textbox?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.