I was doing a project but there was a problem involving OleDbCommand occurring in two different places:
dr_alu = _dataCommand.ExecuteReader();
if (dr_alu.HasRows == true)
dr_reg_notas = _dataCommand.ExecuteReader();
if (dr_reg_notas.HasRows == true)
I have tried almost everything but I can not find a way to fix it. I would be very grateful for some help. Thank you.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
namespace ProjetoEscola
{
public partial class dgv_notas : Form
{
OleDbConnection conn = Conexao.obterConexao();
OleDbConnection dr_alu;
BindingSource bs_alu = new BindingSource();
OleDbConnection dr_disc;
BindingSource bs_disc = new BindingSource();
OleDbConnection dr_menc;
BindingSource bs_menc = new BindingSource();
OleDbConnection dr_reg_notas;
BindingSource bs_reg_notas = new BindingSource();
String _query;
public dgv_notas()
{
InitializeComponent();
}
private void carregar_aluno()
{
_query = "SELECT * from alunos order by nome";
OleDbCommand _dataCommand = new OleDbCommand(_query, conn);
dr_alu = _dataCommand.ExecuteReader();
if (dr_alu.HasRows == true)
{
bs_alu.DataSource = dr_alu;
cmb_aluno.DataSource = bs_alu;
cmb_aluno.DisplayMember = "nome";
cmb_aluno.ValueMember = "matricula";
lbl_matricula.Text = cmb_aluno.SelectedValue.ToString();
}
else
{
MessageBox.Show("Não temos Alunos Cadastrados !!!!", "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
private void carregar_grid()
{
_query = "SELECT Alunos.Nome, Disciplinas.sigla, Disciplinas.descricao, Registro_Mencoes.mencao FROM Disciplinas INNER JOIN (Alunos INNER JOIN Registro_Mencoes ON Alunos.Matricula = Registro_Mencoes.matricula) ON Disciplinas.cod_disciplina = Registro_Mencoes.cod_disciplina order by Alunos.Nome";
OleDbCommand _dataCommand = new OleDbCommand(_query, conn);
dr_reg_notas = _dataCommand.ExecuteReader();
if (dr_reg_notas.HasRows == true)
{
bs_reg_notas.DataSource = dr_reg_notas;
dgv_notas.DataSource = bs_reg_notas;
}
else
{
MessageBox.Show("Não temos Menções Lançadas !!!", "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
private void resigtro_Load(object sender, EventArgs e)
{
carregar_grid();
}
}
}