Ejemplo n.º 1
0
        private void button2_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);
            List <GuideS> Guide = new List <GuideS>();

            try
            {
                conn.Open();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            string query = "select * from Guide";

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

                while (reader.Read())
                {
                    GuideS GS = new GuideS();
                    GS.Tour_guide_id      = reader.GetInt32(reader.GetOrdinal("Tour_guide_id"));
                    GS.Tour_guide_name    = reader.GetString(reader.GetOrdinal("Tour_guide_name"));
                    GS.Tour_guide_email   = reader.GetString(reader.GetOrdinal("Tour_guide_email"));
                    GS.Tour_guide_address = reader.GetString(reader.GetOrdinal("Tour_guide_address"));
                    GS.Tour_guide_phn     = reader.GetString(reader.GetOrdinal("Tour_guide_phn"));
                    GS.Customer_id        = reader.GetString(reader.GetOrdinal("Customer_id"));

                    Guide.Add(GS);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            conn.Close();
            dtgDel.DataSource = Guide;
        }
Ejemplo n.º 2
0
        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    = Convert.ToInt32(tbSearch.Text);
            string query = "select * from Guide where Tour_guide_id = " + id;

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

            GuideS c = new GuideS();

            while (reader.Read())
            {
                c.Tour_guide_id      = reader.GetInt32(reader.GetOrdinal("Tour_guide_id"));
                c.Tour_guide_name    = reader.GetString(reader.GetOrdinal("Tour_guide_name"));
                c.Tour_guide_email   = reader.GetString(reader.GetOrdinal("Tour_guide_email"));
                c.Tour_guide_address = reader.GetString(reader.GetOrdinal("Tour_guide_address"));
                c.Tour_guide_phn     = reader.GetString(reader.GetOrdinal("Tour_guide_phn"));
                c.Customer_id        = reader.GetString(reader.GetOrdinal("Customer_id"));
            }

            conn.Close();

            tbName.Text    = c.Tour_guide_name;
            tbEmail.Text   = c.Tour_guide_email;
            tbAddress.Text = c.Tour_guide_address;
            tbPhn.Text     = c.Tour_guide_phn;
            tbCID.Text     = c.Customer_id;
        }