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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Santhosh Kumar JayaramanRank #563 · 4.3K reputationPosted Jul 23, 2012, 1:43 AM EDT
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
Santhosh Kumar JayaramanRank #563 · 4.3K reputationPosted Jul 20, 2012, 6:38 AM EDT
rashmi kc89 reputationPosted Jul 20, 2012, 6:41 AM EDT
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 JayaramanRank #563 · 4.3K reputationPosted Jul 20, 2012, 6:47 AM EDT
Like
cmd.CommandText = "insert into tblsub(subjectname,ID,Names) values('" + textBox1.Text.ToString() + "','" +Convert.ToInt32( textBox2.Text.ToString()) + "','" + comboBox1.Text.ToString() + "')";
rashmi kc89 reputationPosted Jul 20, 2012, 6:51 AM EDT
Syntax error in INSERT INTO statement.
VulpesRank #55 · 29.2K reputationPosted Jul 20, 2012, 6:55 AM EDT
So I'd try:
cmd.CommandText = "insert into tblsub(subjectname,ID,Names) values('" + textBox1.Text + "'," + textBox2.Text + ",'" + comboBox1.Text + "')";
Santhosh Kumar JayaramanRank #563 · 4.3K reputationPosted Jul 22, 2012, 9:16 PM EDT
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
rashmi kc89 reputationPosted Jul 23, 2012, 12:54 AM EDT
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