string sid = Session["id"].ToString();
            string q1, q2;
            q1 = "select count (*) from All_msg where target_id = '" + sid + "'";
            SqlCommand cmd1 = new SqlCommand(q1, cn);
            int v1;
            v1 = (int)cmd1.ExecuteScalar();

            q2 = "select count (*) from All_msg where target_id = '" + sid + "'";
            SqlCommand cmd2 = new SqlCommand(q2, cn);
            SqlDataReader rdr1 = cmd2.ExecuteReader();
            while (rdr1.Read())
            {
                if (rdr1.HasRows)
                {
                    TableRow tr1 = new TableRow();
                    TableCell t1 = new TableCell();
                    string s1 =  Convert.ToString(rdr1["id"]);
                    t1.Text = s1 ;
                    tr1.Cells.Add(t1);

What Should I do?

Did you receive an error message? Which exception is thrown?

I found new error like : Index was outside the bounds of the array.

TableCell t2 = new TableCell();
                    s1 = rdr1[5].ToString();
                    t2.Text = s1;
                    tr1.Cells.Add(t2);

                    TableCell t3 = new TableCell();
                    t3.Text = rdr1[1].ToString();
                    tr1.Cells.Add(t3);

                    TableCell t4 = new TableCell();
                    t4.Text = (string)rdr1[2].ToString();
                    tr1.Cells.Add(t4);

Change that query statement.

q2 = "select * from All_msg where target_id = '" + sid + "'";
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.