Esempio n. 1
0
        public Post[] GetPost(string profileId)
        {
            String query = "SELECT * FROM [dbo].[Posts] WHERE profile_id='" + profileId + "'" +
                           "ORDER BY postdate ASC;";

            String count = "SELECT * FROM [dbo].[Posts] WHERE profile_id='" + profileId + "'" +
                           "ORDER BY postdate ASC;";
            int counter = 0;

            //Connecting to the DB
            SqlConnection connection = ConnectionSQL.connectDB();

            SqlCommand    command = new SqlCommand(count, connection);
            SqlDataReader reader  = command.ExecuteReader();

            while (reader.Read())
            {
                counter++;
            }

            connection.Close();

            connection = ConnectionSQL.connectDB();


            Post[] posts = new Post[counter];

            command = new SqlCommand(query, connection);
            reader  = command.ExecuteReader();

            counter = 0;

            while (reader.Read())
            {
                Post post = new Post();
                post.PostTime  = reader.GetValue(3).ToString();
                post.PostText  = reader.GetValue(2).ToString();
                posts[counter] = post;
                counter++;
            }

            connection.Close();

            return(posts);
        }
Esempio n. 2
0
        public void PushPost(string id, string text)
        {
            //Connecting to the DB

            SqlConnection connection = ConnectionSQL.connectDB();

            string query = "INSERT INTO Posts(profile_id,post,postdate) VALUES(@ID, @Text, CURRENT_TIMESTAMP)";

            SqlCommand command = new SqlCommand(query, connection);

            command.Parameters.AddWithValue("@ID", id);
            command.Parameters.AddWithValue("@Text", text);
            int run = command.ExecuteNonQuery();

            connection.Close();
            if (run == 0)
            {
                Console.WriteLine("The user could not be created. Please check the inputs for duplicate user!");
            }
        }