Example #1
0
    private void BindMessage()
    {
        string conn = ConfigurationManager.ConnectionStrings["conn"].ConnectionString;

        using (SqlConnection con = new SqlConnection(conn))
        {
            using (SqlCommand cmd = new SqlCommand("select * from Message  WHERE TargetID ='" + Convert.ToInt32(Session["KullaniciID"]) + "'", con))
            {
                using (SqlDataAdapter sda = new SqlDataAdapter(cmd))
                {
                    DataTable dt = new DataTable();
                    sda.Fill(dt);
                    RepMessage.DataSource = dt;
                    RepMessage.DataBind();
                }
            }
        }
    }
Example #2
0
    private void BindMessage()
    {
        string conn = ConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionString;

        using (SqlConnection con = new SqlConnection(conn))
        {
            using (SqlCommand cmd = new SqlCommand(" SELECT dbo.[User].*, dbo.Message.* FROM  dbo.Message INNER JOIN dbo.[User] ON dbo.Message.SenderID = dbo.[User].UserID  WHERE TargetID ='" + Convert.ToInt32(Session["KullaniciID"]) + "'", con))
            {
                using (SqlDataAdapter sda = new SqlDataAdapter(cmd))
                {
                    DataTable dt = new DataTable();
                    sda.Fill(dt);
                    Session.Add("MesajSayisi", dt.Rows.Count.ToString());
                    //string[] msgArr = new string[dt.Rows.Count];
                    //for (int i = 0; i < dt.Rows.Count; i++)//bosuna ugrastin amk .
                    //{
                    //    string someDate = dt.Rows[i]["SendDate"].ToString();
                    //    DateTime startDate = DateTime.Parse(someDate);
                    //    DateTime now = DateTime.Now;
                    //    TimeSpan elapsed = now.Subtract(startDate);
                    //    double daysAgo = elapsed.TotalDays;
                    //    msgArr[i]= daysAgo.ToString("0");
                    //    //Session.Add("DaysAgo", daysAgo.ToString("0"));//item databoundda yapman lazim
                    //    //messages = Session["SeatNum"] as List<string>;
                    //}
                    //Session["Days"] = msgArr;
                    RepMessage.DataSource = dt;
                    RepMessage.DataBind();
                    if (dt.Rows.Count == 0)
                    {
                        RepMessage.Visible = false;
                        zeroMsg.Visible    = true;
                    }
                }
            }
        }
    }