public bool submitResult(EmployeeBO obj) { string conn = @"Data Source=(LocalDB)\v11.0;AttachDbFilename=C:\Users\asim.irshad\Documents\GitHub\TestERP\ERPBackend\ERPdb.mdf;Integrated Security=True"; SqlConnection con = null; try { con = new SqlConnection(conn); con.Open(); SqlCommand cmd = new SqlCommand("Insert into Employee(Id, Name, Address, Phone, CNIC) Values(@i , @n , @a , @p , @c);", con); cmd.Parameters.Add(new SqlParameter("@i", obj.Id)); cmd.Parameters.Add(new SqlParameter("@n", obj.Name)); cmd.Parameters.Add(new SqlParameter("@a", obj.Address)); cmd.Parameters.Add(new SqlParameter("@p", obj.Phone)); cmd.Parameters.Add(new SqlParameter("@c", obj.CNIC)); cmd.ExecuteNonQuery(); con.Close(); return true; } catch (Exception) { con.Close(); return false; } }
private void submit_Click(object sender, EventArgs e) { EmployeeBO obj = new EmployeeBO(); obj.Id = Int32.Parse(tid.Text); obj.Name = tname.Text; obj.Address = taddress.Text; obj.Phone = tphone.Text; obj.CNIC = mtcnic.Text; DataAccesser d = new DataAccesser(); if(d.submitResult(obj)) { MessageBox.Show("Employee successfully added"); } else { MessageBox.Show("Employee not added"); } tid.Text = ""; tname.Text = ""; taddress.Text = ""; tphone.Text = ""; mtcnic.Text = ""; }