Ejemplo n.º 1
0
        public static void stergere()
        {
            CONNECT conn = new CONNECT();

            conn.openConnection();
            SqlCommand command = new SqlCommand("DELETE FROM Meniu", conn.getConnection());

            command.ExecuteNonQuery();
            conn.closeConnection();
        }
Ejemplo n.º 2
0
        public static void intializare()
        {
            CONNECT      conn    = new CONNECT();
            SqlCommand   command = new SqlCommand();
            StreamReader sr      = new StreamReader(Application.StartupPath + @"\Resurse_C#\meniu.txt");

            char[] split = { ';' };
            string sir;

            conn.openConnection();
            sir = sr.ReadLine();
            while ((sir = sr.ReadLine()) != null)
            {
                string[] siruri = sir.Split(split);
                string   query  = "INSERT INTO Meniu(id_produs,denumire_produs,descriere,pret,kcal,felul) VALUES (@id,@nume,@desc,@pret,@kcal,@felul)";

                //@id,@nume,@desc,@pret,@kcal,@felul
                //command.CommandText = query;
                //command.Connection = conn.getConnection();
                command = new SqlCommand(query, conn.getConnection());

                if (siruri[0].Trim() != "")
                {
                    command.Parameters.Add("id", SqlDbType.Int).Value       = Convert.ToInt32(siruri[0].Trim());
                    command.Parameters.Add("nume", SqlDbType.VarChar).Value = siruri[1].ToString();
                    command.Parameters.Add("desc", SqlDbType.NText).Value   = siruri[2].ToString();
                    command.Parameters.Add("pret", SqlDbType.Int).Value     = Convert.ToInt32(siruri[3].ToString());
                    command.Parameters.Add("kcal", SqlDbType.Int).Value     = Convert.ToInt32(siruri[4].ToString());
                    command.Parameters.Add("felul", SqlDbType.Int).Value    = Convert.ToInt32(siruri[5].ToString());

                    command.ExecuteNonQuery();
                }
            }

            conn.closeConnection();
        }