コード例 #1
0
        public ActionResult <IEnumerable <CarType> > ToType()
        {
            var authors = new List <CarType>();

            using (SqlConnection connection = new SqlConnection(_connectionString))
            {
                string     sql     = "select * from cartype";
                SqlCommand command = new SqlCommand(sql, connection);
                connection.Open();
                SqlDataReader reader = command.ExecuteReader();
                while (reader.Read())
                {
                    authors.Add(HelperOper.ADONetToClass <CarType>(reader));
                }
            }

            return(Ok(authors));
        }
コード例 #2
0
        public ActionResult <IEnumerable <CarInfo> > SelectCarOper(string carname, int carP, int carTyep)
        {
            var authors = new List <CarInfo>();

            using (SqlConnection connection = new SqlConnection(_connectionString))
            {
                string     sql     = $"select * from CarType c join CarInfo i on c.CarTypeID=i.cid join CarBrand b on i.bid = b.CarBrandID join AllCars a on i.CarInfoID = a.CarInfoid join Va v on a.Vaid = v.VID join CarType c2 on v.cid = c2.CarTypeID join CarBrand b2 on v.bid = b2.CarBrandID where v.Vstate = 1 and i.CarName like '%{carname}%' or c.CarTypeID={carP} or b.CarBrandID={carTyep}";
                SqlCommand command = new SqlCommand(sql, connection);
                connection.Open();
                SqlDataReader reader = command.ExecuteReader();
                while (reader.Read())
                {
                    authors.Add(HelperOper.ADONetToClass <CarInfo>(reader));
                }
            }

            return(Ok(authors));
        }