Click here to Skip to main content
15,885,757 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
my Code is that in that code always occurred syntax error in update statement.in my combo box data is filled from the database.

code.
C#
void shw_group()
       {


           try
           {
               s = "select * from create_group";

               da = new OleDbDataAdapter(s, cn);
               DataSet ds = new DataSet();
               da.Fill(ds, "set");
               cmb_group_name.DataSource = ds;
               cmb_group_name.DisplayMember = "set.group";
           }
           catch (Exception ea)
           {
               MessageBox.Show(ea.Message);
           }
       }


C#
private void button1_Click(object sender, EventArgs e)
        {
            upd();
        }
        void upd()
        {
            string group_name;
            group_name = cmb_group_name.Text;
            string s = "update persn_info set group ="+group_name+" where sub_no="+ txt_sub_no.Text;
            cm = new OleDbCommand(s, cn);
            //cm.Parameters.AddWithValue("@group", group_name);


            cn.Open();
            cm.ExecuteNonQuery();
            cn.Close();
            MessageBox.Show("Subscriber information is updated", "Di-Count", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
Posted
Comments
BharatPrajapati212 27-Sep-14 8:40am    
use cmb_group_name.DataSource = ds.Tables["set"];

1 solution

You have pass alias Name of Dataset object ds.
So you have to pass that alias name when you give datasource of ComboBox Control

C#
cmb_group_name.DataSource = ds.Tables["set"];
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900