Пример #1
0
        public bool suaHanhKhach(HanhKhach hK)
        {
            SqlConnection sqlConnection = createConnection();

            try
            {
                sqlConnection.Open();
                string SQL = "UPDATE HANH_KHACH SET TenHK = '" + hK.TenHK + "', CMND = '" + hK.CMND + "', DienThoai = '" + hK.DienThoai + "' WHERE MaHK = '" + hK.MaHK + "'";

                SqlCommand cmd = new SqlCommand(SQL, sqlConnection);

                // Query và kiểm tra
                if (cmd.ExecuteNonQuery() > 0)
                {
                    return(true);
                }
            }
            catch (Exception e)
            {
                throw e;
            }
            finally
            {
                // Dong ket noi
                sqlConnection.Close();
            }
            return(false);
        }
Пример #2
0
        public bool themHanhKhach(HanhKhach hK)
        {
            SqlConnection sqlConnection = createConnection();

            try
            {
                sqlConnection.Open();
                //SqlCommand cmd = new SqlCommand("INSERT INTO SAN_BAY(MaSB,TenSB) VALUES ('" + txtMaSB.Text + "',N'" + txtTenSB.Text + "')", con);

                string     SQL = "INSERT INTO HANH_KHACH(MaHK, TenHK, CMND, DienThoai) VALUES ('" + hK.MaHK + "','" + hK.TenHK + "', '" + hK.CMND + "', '" + hK.DienThoai + "')";
                SqlCommand cmd = new SqlCommand(SQL, sqlConnection);
                // Query và kiểm tra
                if (cmd.ExecuteNonQuery() > 0)
                {
                    return(true);
                }
            }
            catch (Exception e)
            {
                throw e;
            }
            finally
            {
                // Dong ket noi
                sqlConnection.Close();
            }
            return(false);
        }
Пример #3
0
        public DataTable GetDataTimKiemHK(HanhKhach hK)
        {
            SqlConnection  sqlConnection  = createConnection();
            string         sql            = "SELECT MaHK, TenHK, CMND, DienThoai FROM HANH_KHACH WHERE (MaHK = '" + hK.MaHK + "') OR (TenHK LIKE '%" + hK.TenHK + "%') OR (CMND = '" + hK.CMND + "') OR (DienThoai ='" + hK.DienThoai + "')";
            SqlCommand     cmd            = new SqlCommand(sql, sqlConnection);
            SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(sql, sqlConnection);
            DataSet        ds             = new DataSet();

            sqlDataAdapter.Fill(ds);
            //SqlCommand cmd = new SqlCommand("SELECT *  FROM DOIBONG", sqlConnection);
            //SqlDataAdapter da = new SqlDataAdapter(cmd);
            //DataSet ds = new DataSet();
            //da.Fill(ds);
            //DGVHienThi.DataSource = ds.Tables[0];
            //DGVHienThi.Refresh();
            return(ds.Tables[0]);
        }