public class CustomerService { public List<Customers> ShowAll() { List<Customers> customers = new List<Customers>(); SqlConnection conn = new SqlConnection("data source=.; database=custer; user id=sa; password=*****"); SqlCommand cmd = new SqlCommand(" select * from Customers ", conn.Open()); SqlDataReader dr = cmd.ExecuteReader(); while (dr.Read()) { Customer customer = new Customer () { CustomerID = dr.GetInt32(0), CustomerName = dr.GetString(1), CustomerSurname = dr.GetString(2), }; customers.Add(customer); } conn.Close(); return customers; } } private void button1_Click(object sender, EventArgs e) { CustomerService service = new CustomerService(); if (txtCustomerName.Text != "" || txtCustomerSurname.Text != "") { musteriservice.MusteriEkle(txtCustomerName.Text, txtCustomerSurname.Text); //this rows is other method .I am using for adding new customer MessageBox.Show("Customer Added"); Form1.dataGridView1.DataSource = service.ShowAll(); Form1.dataGridView1.Refresh(); } else { //…………… } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)