示例#1
0
        private void LoadData_Click(object sender, EventArgs e)
        {
            string connString = @"Server=LAPTOP-D3473TU4;Database=Project;Integrated Security=true;";
            //string connString = @"Server=DESKTOP-L6S3T5O\SQLEXPRESS; Database=Project ;Integrated Security=true;";
            SqlConnection    conn     = new SqlConnection(connString);
            List <Customer1> Customer = new List <Customer1>();


            conn.Open();


            string        query  = "select * from Customer ";
            SqlCommand    cmd    = new SqlCommand(query, conn);
            SqlDataReader reader = cmd.ExecuteReader();

            while (reader.Read())
            {
                Customer1 c = new Customer1();
                c.Customer_Id    = reader.GetInt32(reader.GetOrdinal("Customer_Id"));
                c.Customer_name  = reader.GetString(reader.GetOrdinal("Customer_name"));
                c.Pack_name      = reader.GetString(reader.GetOrdinal("Pack_name"));
                c.Pack_id        = reader.GetString(reader.GetOrdinal("Pack_id"));
                c.Customer_phone = reader.GetString(reader.GetOrdinal("Customer_phone"));
                c.Customer_email = reader.GetString(reader.GetOrdinal("Customer_email"));
                c.Purchase_time  = reader.GetString(reader.GetOrdinal("Purchase_time"));
                Customer.Add(c);
            }

            conn.Close();
            dtCustomer.DataSource = Customer;
        }
        private void btnSearch_Click(object sender, EventArgs e)
        {
            //string connString = @"Server=LAPTOP-D3473TU4;Database=Project;Integrated Security=true;";
            string connString = @"Server=DESKTOP-L6S3T5O\SQLEXPRESS; Database=Project ;Integrated Security=true;";
            //string connString = @"Server=NEEHAL\SQLEXPRESS;Database=Project;Integrated Security=true;";
            //string connString = @"Server=DESKTOP-VCKBA6J\SQLEXPRESS; Database=Project ;Integrated Security=true;";
            SqlConnection conn = new SqlConnection(connString);

            try
            {
                conn.Open();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            int    id    = Int32.Parse(tbSrchCId.Text);
            string query = "select * from Customer where Customer_id = " + id;

            SqlCommand    cmd    = new SqlCommand(query, conn);
            SqlDataReader reader = cmd.ExecuteReader();

            Customer1 c = new Customer1();

            while (reader.Read())
            {
                c.Customer_Id    = reader.GetInt32(reader.GetOrdinal("Customer_Id"));
                c.Customer_name  = reader.GetString(reader.GetOrdinal("Customer_name"));
                c.Pack_name      = reader.GetString(reader.GetOrdinal("Pack_name"));
                c.Pack_id        = reader.GetString(reader.GetOrdinal("Pack_id"));
                c.Customer_phone = reader.GetString(reader.GetOrdinal("Customer_phone"));
                c.Customer_email = reader.GetString(reader.GetOrdinal("Customer_email"));
                c.Purchase_time  = reader.GetString(reader.GetOrdinal("Purchase_time"));
            }

            conn.Close();

            tbCNameUpdate.Text  = c.Customer_name;
            tbPNameUpdate.Text  = c.Pack_name;
            tbPIdUpdate.Text    = c.Pack_id;
            tbCPhoneUpdate.Text = c.Customer_phone;
            tbCEmailUpdate.Text = c.Customer_email;
            dtUpdate.Text       = c.Purchase_time;
        }