コード例 #1
0
        private List <Tweet> getTweets(string strUserName)
        {
            List <Tweet> TweetList = new List <Tweet>();

            //DataSet ds = new DataSet();
            //SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["ConString"]);
            //SqlCommand cmd = new SqlCommand();
            //string Query = @"SELECT * from Tweet As T (nolock) Join Following as FG (nolock) on FG.user_Id = T.user_Id    where FG.following_Id = @userid order by created desc UNION SELECT * from Tweet As T (nolock) Join Following as FR (nolock) on FG.[following_Id] = T.user_Id Where FG.[following_Id] = @userid order by created desc";
            //cmd = new SqlCommand(Query, con);
            //cmd.Parameters.AddWithValue("@UserID", strUserName);
            //SqlDataAdapter sda = new SqlDataAdapter(Query, con);
            //con.Open();
            //sda.Fill(ds);
            //con.Close();

            //if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            //{
            //    for (int i=0; i < ds.Tables[0].Rows.Count; i++ )
            //    {
            //         Tweet obj = new Tweet();
            //         obj.user_id = ds.Tables[0].Rows[i]["user_id"].ToString();
            //         obj.message = ds.Tables[0].Rows[i]["message"].ToString();
            //         string strDate = ds.Tables[0].Rows[i]["created"].ToString();
            //         obj.created = Convert.ToDateTime(strDate).Date.ToShortDateString();
            //         if (Convert.ToDateTime(strDate).Date== DateTime.Now.Date)
            //         {
            //             obj.created = Convert.ToDateTime(strDate).TimeOfDay.ToString();
            //         }
            //         TweetList.Add(obj);
            //    }
            //}
            testEntities dbTweetsEntity = new testEntities();

            TweetList = dbTweetsEntity.getAllTweets(strUserName).ToList(); //getAllTweets is a stored procedure which will return the all the tweets.

            return(TweetList);
        }