I am getting error pls check and find the error
I need to insert the ID and names to the table subject but m getting error
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Santhosh Kumar JayaramanPosted Jul 23, 2012, 5:43 AM
private void Form1_Load(object sender, EventArgs e)
{
OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Application.StartupPath + "\\school1.mdb");
OleDbDataAdapter dadpter = new OleDbDataAdapter("select * from tblclass", con);
DataSet dset = new DataSet();
dadpter.Fill(dset);
comboBox1.DisplayMember= "classname"; // to display roll no. in combobox
comboBox1.ValueMember = "classcode"; // to store name as value of combobox for selected roll no.
comboBox1.DataSource = dset.Tables[0];
}
Then In the selectedindex changed event of combobox 1, load the subject dropdown for the selected class.
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
{
textBox2.Text = comboBox1.SelectedValue.ToString();
OleDbConnection con1 = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Application.StartupPath + "\\school1.mdb");
OleDbDataAdapter dadpter1 = new OleDbDataAdapter("select * from tblsubject where classcode= "+Convert.ToInt32(comboBox1.SelectedValue), con1);
DataSet dset1 = new DataSet();
dadpter1.Fill(dset1);
comboBox2.DisplayMember = "subjectname"; // to display roll no. in combobox
comboBox2.ValueMember = "subjectcode"; // to store name as value of combobox for selected roll no.
comboBox2.DataSource = dset1.Tables[0];
}
If you see the query , i have a where condition to fetch only subjects for the selected class.
Then In the selectedindex changed event of combobox 2, load the branch dropdown for the selected class and selected subject..
Like this.
private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
{
textBox3.Text = comboBox2.SelectedValue.ToString();
OleDbConnection con2 = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Application.StartupPath + "\\school1.mdb");
OleDbDataAdapter dadpter2 = new OleDbDataAdapter("select * from tblbranch where classcode= " + Convert.ToInt32(comboBox1.SelectedValue) + " and subjectcode= "+Convert.ToInt32(comboBox2.SelectedValue) , con2);
DataSet dset2 = new DataSet();
dadpter2.Fill(dset2);
comboBox4.DataSource = dset2.Tables[0];
comboBox4.DisplayMember = "branchname"; // to display roll no. in combobox
comboBox4.ValueMember = "branchcode"; //
}
.....
It goes like this.
Hope this would help you.Please let us know if you face difficulties
rashmi kcPosted Jul 23, 2012, 4:54 AM
all branchcode ,subjectcode,classcode should be saved along with classcombobox,subject everthing and it s working properly.
but in each subjectscombobox , branchcombobox all the classstandard subjects and branches are displaying
How to bind one combobox into another and When i saved , its ID also should save
If i have classcombobox once i select 10th std in class only 10th subject should display in the subjectcombobox , and if i select Science from its branch should display in branchcombobox as physics,chemistry
how to do this
pls check my sourcecode
Santhosh Kumar JayaramanPosted Jul 23, 2012, 1:16 AM
cmd.CommandText = "insert into tblsub(subjectname,[ID],[Names]) values('" + textBox1.Text + "','" + textBox2.Text + "','" + comboBox1.Text + "')";
and the reason is they are keywords.better try to avoid column names same as keyword names
VulpesPosted Jul 20, 2012, 10:55 AM
So I'd try:
cmd.CommandText = "insert into tblsub(subjectname,ID,Names) values('" + textBox1.Text + "'," + textBox2.Text + ",'" + comboBox1.Text + "')";
rashmi kcPosted Jul 20, 2012, 10:51 AM
Syntax error in INSERT INTO statement.
Santhosh Kumar JayaramanPosted Jul 20, 2012, 10:47 AM
Like
cmd.CommandText = "insert into tblsub(subjectname,ID,Names) values('" + textBox1.Text.ToString() + "','" +Convert.ToInt32( textBox2.Text.ToString()) + "','" + comboBox1.Text.ToString() + "')";
rashmi kcPosted Jul 20, 2012, 10:41 AM
but when i press the button ths error s coming
I checked everythng still m getting an error
Syntax error in INSERT INTO statement.
Santhosh Kumar JayaramanPosted Jul 20, 2012, 10:38 AM