I am developing an application in which i have four comboBoxes i-e (comboBox1 for class, comboBox2 for group, comboBox3 for section and combBox4 for months) and a listBox. i have fetched data from database to all of these comboBoxes in "OnLoad Function".Now i want to show student names in listBox according to the comboBoxes. i-e when i select "class 7th" from class (comboBox1). It should display those students who are in selected class (class 7th), selected group (selected in comboBox2) and selected section (selected in comboBox3). Here is my code but it gives me SQL syntax exception and indexOutOfRange exception. The database attached is in mysql. "dbOperation" is the object of the class "myDatabse" in which I have connected the database and implemented all queries.
public partial class FeeVoucherPrint : Form
{
myDatabase dbOperation = new myDatabase();
DataTable table = new DataTable();
public FeeVoucherPrint()
{
InitializeComponent();
this.MaximizeBox = false;
this.MinimizeBox = false;
}
private void FeeVoucherPrint_Load(object sender, EventArgs e)
{
table = dbOperation.select("* from class");
comboBox1.DataSource = table;
comboBox1.DisplayMember = "name";
comboBox1.ValueMember = "id";
table = dbOperation.select("* from `group`");
comboBox2.DataSource = table;
comboBox2.DisplayMember = "name";
comboBox2.ValueMember = "id";
table = dbOperation.select("* from section");
comboBox3.DataSource = table;
comboBox3.DisplayMember = "name";
comboBox3.ValueMember = "id";
table = dbOperation.select("* from months");
comboBox4.DataSource = table;
comboBox4.DisplayMember = "month";
comboBox4.ValueMember = "id";
}
private void fill()
{
try
{
table = dbOperation.select("studentid from studentinclass where classid = " + comboBox1.SelectedValue + " and groupid = " + comboBox2.SelectedValue);
table = dbOperation.select("* from student where studid = " + table.Rows[0]["studentid"]);
listBox1.DataSource = table;
listBox1.DisplayMember = "name";
listBox1.ValueMember = "studid";
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
private void button1_Click(object sender, EventArgs e)
{
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
fill();
}
private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
{
fill();
}
private void comboBox3_SelectedIndexChanged(object sender, EventArgs e)
{
fill()
}
}