Пример #1
0
        // to return List of restorents
        public List <Restorent> ToSelectRestorentDetails()
        {
            List <Restorent> rlist = new List <Restorent>();
            string           query = "select * from Reaustaurant";

            try
            {
                using (SqlConnection connection = new SqlConnection(connection_string))
                {
                    connection.Open();
                    SqlCommand    command = new SqlCommand(query, connection);
                    SqlDataReader sdr     = command.ExecuteReader();



                    while (sdr.Read())
                    {
                        Restorent r = new Restorent();
                        r.id        = sdr.GetInt32(0);
                        r.Rname     = sdr.GetString(1);
                        r.Rlocation = sdr.GetString(2);
                        r.Rating    = sdr.GetInt32(3);

                        rlist.Add(r);
                    }
                }
            }
            catch (Exception e) { Console.WriteLine(e.Message); }
            return(rlist);
        }
Пример #2
0
        // to insert data
        public void ToInsertRestorentDetails(Restorent r)
        {
            string query = "insert into Reaustaurant values('" + r.id + "','" + r.Rname + "','" + r.Rlocation + "','" + r.Rating + "')";

            try
            {
                using (SqlConnection connection = new SqlConnection(connection_string))
                {
                    connection.Open();
                    SqlCommand command = new SqlCommand(query, connection);
                    Console.WriteLine("{0} Rows inserted", command.ExecuteNonQuery());
                }
            }
            catch (Exception e) { Console.WriteLine(e.Message); }
        }
Пример #3
0
        // set restorent data
        public Restorent SetResrorentDetails()
        {
            Restorent rs = new Restorent();

            Console.WriteLine("Enter Id:");
            rs.id = int.Parse(Console.ReadLine());

            Console.WriteLine("Enter restorent name:");
            rs.Rname = Console.ReadLine();

            Console.WriteLine("Enter location:");
            rs.Rlocation = Console.ReadLine();

            Console.WriteLine("Enter rating 1-5:");
            rs.Rating = int.Parse(Console.ReadLine());

            return(rs);
        }