private void button1_Click(object sender, EventArgs e) { try { String _name = Name_Textbox.Text; int _number; if (!(int.TryParse(Number_Textbox.Text, out _number))) { // MessageBox.Show("Invalid Number"); label4.Visible = true; } else { PhoneDirectory phone = new PhoneDirectory(_name, _number); BusinessLayer phoneDetail = new BusinessLayer(); bool result=phoneDetail.ValidateAndAdd(phone); if (result == true) { dataGridView1.DataSource = phoneDetail.ViewPhone(phone); Number_Textbox.Clear(); Name_Textbox.Clear(); } else { MessageBox.Show("cannot be Added"); } } } catch(Exception e1) { MessageBox.Show(e1.Message); } }
private void button2_Click(object sender, EventArgs e) { BusinessLayer phoneDetail = new BusinessLayer(); dataGridView1.DataSource = phoneDetail.Search(textBox3.Text); //int _number; //String _name; //if (int.TryParse(textBox3.Text, out _number)) //{ // DataTable t = phoneDetail.Search("select * from Phone_dir where Phone=@phone", _number); //} //else //{ // _name = textBox3.Text; // DataTable t = phoneDetail.Search("select * from Phone_dir where Name=@phone", _name); //} //SqlDataAdapter _dataadapter; //using (SqlConnection sq = new SqlConnection("Server=localhost;Database=phone_directory;Trusted_Connection=true")) //{ // sq.Open(); // if (int.TryParse(textBox3.Text, out _number)) // { // _dataadapter = new SqlDataAdapter("select * from Phone_dir where Phone=@phone", sq); // _dataadapter.SelectCommand.Parameters.AddWithValue("@phone", _number); // } // else // { // _name = textBox3.Text; // _dataadapter = new SqlDataAdapter("select * from Phone_dir where Name=@name", sq); // _dataadapter.SelectCommand.Parameters.AddWithValue("@name", _name); // } // DataTable t = new DataTable(); // _dataadapter.Fill(t); // dataGridView1.DataSource = t; //} textBox3.Clear(); }