If i select the item as physics in the subject combobox ,Its all chapters should display in the checkboxlist.
similarly if I select Chemistry Its all chapter should display in the chechboxlist
How to do this using windows form application c# with Access database
rashmi kcPosted Jul 14, 2012, 1:53 AM
rashmi kcPosted Jul 10, 2012, 1:46 PM
Satyapriya NayakPosted Jul 10, 2012, 1:27 PM
Try this...
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 Combobox
{
public partial class Form1 : Form
{
string ConnectionString = System.Configuration.ConfigurationSettings.AppSettings["dsn"];
OleDbCommand com;
OleDbDataAdapter oda;
DataSet ds;
string str;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
comboBox1.Items.Add("Choose subject");
OleDbConnection con = new OleDbConnection(ConnectionString);
con.Open();
str = "select sub from subject group by sub";
com = new OleDbCommand(str, con);
OleDbDataReader reader = com.ExecuteReader();
while (reader.Read())
{
comboBox1.Items.Add(reader["sub"]);
}
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
checkedListBox1.Items.Clear();
OleDbConnection con = new OleDbConnection(ConnectionString);
con.Open();
str = "select * from subject where sub='" + comboBox1.Text.Trim() + "'";
com = new OleDbCommand(str, con);
OleDbDataReader reader = com.ExecuteReader();
while (reader.Read())
{
checkedListBox1.Items.Add(reader["chapter"].ToString());
}
con.Close();
reader.Close();
}
}
}
Thanks
If this post helps you mark it as answer