I have 2 tables in database, tblIPAddress and tblDepartment.
On click of update button, I managed to update everything except for for 1 column(DepartmentID) because of the way I add items on the combobox(cmbDepartment).
DepartmentID column is numbers only. I am identifying each department by ID Number.
Example: 1=IT, 2=Accounts etc.
My question is how to update the column (DepartmentID) with numbers equal to the selected department in combobox?
Code I use to add items on combobox (cmbDepartment)
string query = "select ID, Department from tblDepartment";
OleDbDataAdapter da = new OleDbDataAdapter(query, myConn);
DataSet dsdpt = new DataSet();
da.Fill(dsdpt, "tblDepartment");
cmbDepartment.DataSource = dsdpt.Tables["tblDepartment"];
cmbDepartment.ValueMember = "ID";
cmbDepartment.DisplayMember = "Department";
Code I use to update table(tblIPAddress)
OleDbCommand command = new OleDbCommand();
command.Connection = myConn;
string query = "";
query = "update tblIPAddress set E_Name=@E_Name, DepartmentID=@DepartmentID , E_Username=@E_Username, E_Password=@E_Password, E_Extension=@E_Extension, E_MobileNo=@E_MobileNo, Remarks=@Remarks, Modified_by=@Modified_by, Modified_on=@Modified_on where IP_Address=@IP_Address";
command.CommandText = query;
command.Parameters.AddWithValue("@E_Name", this.txtname.Text);
command.Parameters.AddWithValue("@E_Username", this.txtusern.Text);
command.Parameters.AddWithValue("@E_Password", this.txtpwd.Text);
command.Parameters.AddWithValue("@E_Extension", this.txtext.Text);
command.Parameters.AddWithValue("@E_MobileNo", this.txtmobile.Text);
command.Parameters.AddWithValue("@Remarks", this.txtrmk.Text);
command.Parameters.AddWithValue("@Modified_by", Loginfrm.userlogged);
command.Parameters.AddWithValue("@Modified_on", DateTime.Today.ToShortDateString());
command.Parameters.AddWithValue("@IP_Address", this.txtip.Text);
command.Parameters.AddWithValue("@DepartmentID", this.cmbDepartment.Text);
command.ExecuteNonQuery();
MessageBox.Show("IP Details Updated");