I am getting the error while I am trying to insert a new item into combo box
Error: Items collection cannot be modified when the DataSource property is set.
string connectionstring = "MultipleActiveResultSets=True;Data Source=ECSTSRD;Initial Catalog=PMIDB;User ID=pnpuser;Password=pnpuser123";
sqlConnection myconnection = new SqlConnection(connectionstring);
myconnection.Open();
string custPOsql = "INSERT INTO cust_po (cust_code, po_no) VALUES (@cust_code, @po_no)";
SqlCommand custPOcom = new SqlCommand(custPOsql, myconnection);
custPOcom.Parameters.AddWithValue("@cust_code", cboCustCode.Text);
custPOcom.Parameters.AddWithValue("@po_no", cboPO.Text);
custPOcom.ExecuteNonQuery();
MessageBox.Show("Insert Successfully", "Insert");
cboPO.Items.Add(cboPO.Text);
FYI, I bind the data source of PO combobox in form load.
I have found few similar question in stackoverflow as well as others forums, the way they mention is using cboPO.Items.Add(cboPO.Text) to add new item into combo box, but I could not use it as error shown.
Do anyone know what is the problem, please help.
Thanks in advance.