I am designing windows application using 3-tier architecture. One of my forms contain dynamically generated controls. My question is that How can I save multiple values from controls in my database. I have used return statement but since it returns only
one value my database stored only one value from each of the control. Basically I am creating BILL FORM.
I have created 8 methods one for each control and pass their values in business logic layer's function, but instead of saving multiple values it saved only one value of each control as mentioned above. I tried to use Tuples also but then it gave me "CONVERSION EXCEPTION"
One of my 8 methods is:
It's Tuple version:
My business layer function(Tuple Version):
Programming behind my save button(Tuple Version):
I have created 8 methods one for each control and pass their values in business logic layer's function, but instead of saving multiple values it saved only one value of each control as mentioned above. I tried to use Tuples also but then it gave me "CONVERSION EXCEPTION"
One of my 8 methods is:
public string combo_box_1() { foreach (Control ctrl in this.Controls) { if (ctrl is ComboBox) { if (ctrl.Name.Equals("combo_box_1")) { string main_category = ctrl.Text; string[] arr1 = { main_category }; foreach (string alph in arr1) { MessageBox.Show(alph); return alph; } return main_category; } } } return null; }
It's Tuple version:
public Tuple<string> combo_box_1() { foreach (Control ctrl in this.Controls) { if (ctrl is ComboBox) { if (ctrl.Name.Equals("combo_box_1")) { string main_category = ctrl.Text; Tuple<string> txt2 = new Tuple<string>(main_category); return txt2; } } } return null; }
My business layer function(Tuple Version):
public bool save_bill(Tuple<string> CB1, Tuple<string> CB2, Tuple<string> CB3, Tuple<string> CB4, Tuple<string> NUD1, Tuple<string> CB5, Tuple<string> TB1, Tuple<string> TB2) { try { DAL obj = new DAL(); obj.OpenConnection(); obj.LoadSpParameters("save_bill", CB1, CB2, CB3, CB4, NUD1, CB5, TB1, TB2); obj.ExecuteQuery(); obj.UnLoadSpParameters(); obj.CloseConnection(); return true; } catch (Exception) { return false; } }
Programming behind my save button(Tuple Version):
private void save_button_Click(object sender, EventArgs e) { BLL obj = new BLL(); bool obj2 = obj.save_bill(combo_box_1(), combo_box_2(), combo_box_3(), combo_box_4(), numeric_up_down_1(), combo_box_5(), txt_box_1(), txt_box_2()); if (obj2 == true) { MessageBox.Show("bill saved"); } else { MessageBox.Show("bill cannot be saved"); } }