Exemple #1
0
        public List <Short> GetDataValue()
        {
            List <Short>  returnmodel = new List <Short>();
            Shortener     sh          = new Shortener();
            string        path        = sh.BaseConnection();
            SqlConnection con         = new SqlConnection(path);

            con.Open();
            string        command = "Select * From UrlTable";
            SqlCommand    com     = new SqlCommand(command, con);
            SqlDataReader reader  = com.ExecuteReader();

            while (reader.Read())
            {
                Short ss = new Short
                {
                    ID           = Convert.ToInt32(reader.GetValue(0)),
                    URL          = reader.GetValue(1).ToString(),
                    ShortenedURL = reader.GetValue(2).ToString(),
                    Clicked      = reader.GetValue(3).ToString(),
                    DataCreated  = reader.GetValue(4).ToString()
                };
                returnmodel.Add(ss);
            }
            reader.Close();
            con.Close();
            return(returnmodel);
        }
Exemple #2
0
        public void DeleteString(int id)
        {
            Shortener     sh   = new Shortener();
            string        path = sh.BaseConnection();
            SqlConnection con  = new SqlConnection(path);

            con.Open();
            string     command = "Delete * From UrlTable Where ID='" + id + "'";
            SqlCommand cmd     = new SqlCommand(command, con);

            cmd.Parameters.AddWithValue("@ID", "ID");
            cmd.ExecuteNonQuery();
        }