Note that there are some explanatory texts on larger screens.

plurals
  1. POMultiple records displayed due to code
    primarykey
    data
    text
    <p>Hello Im getting multiple records displayed and they arent descending in order correctly when I insert on button click.</p> <p>The text is added to the database and it is displayed but I get two sets of records displayed on the page and the text from the insert is pushed down to the bottom of the first multiple record.</p> <p>How can I correct this so I only get one return on the page and the comment(text from db) is set to desc.</p> <p>Code: </p> <pre><code> protected void Page_Load(object sender, EventArgs e) { string theUserId = Session["UserID"].ToString(); PopulateWallPosts(theUserId); } private void PopulateWallPosts(string userId) { using (OdbcConnection cn = new OdbcConnection("Driver={MySQL ODBC 3.51 Driver}; Server=localhost; Database=gymwebsite2; User=x; Password=x;")) { cn.Open(); using (OdbcCommand cmd = new OdbcCommand("SELECT Wallpostings FROM WallPosting WHERE UserID=" + userId + " ORDER BY idWallPosting DESC", cn)) { using (OdbcDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { System.Web.UI.HtmlControls.HtmlGenericControl div = new System.Web.UI.HtmlControls.HtmlGenericControl("div"); div.Style["float"] = "left"; Image img = new Image(); img.ImageUrl = "~/userdata/2/uploadedimage/batman-for-facebook.jpg"; img.AlternateText = "Test image"; div.Controls.Add(img); test1.Controls.Add(div); System.Web.UI.HtmlControls.HtmlGenericControl div1 = new System.Web.UI.HtmlControls.HtmlGenericControl("div"); div1.InnerText = String.Format("{0}", reader.GetString(0)); div1.Style["float"] = "left"; test1.Controls.Add(div1); System.Web.UI.HtmlControls.HtmlGenericControl div2 = new System.Web.UI.HtmlControls.HtmlGenericControl("div"); div2.Style["clear"] = "both"; test1.Controls.Add(div2); } } } } } protected void Button1_Click(object sender, EventArgs e) { string theUserId = Session["UserID"].ToString(); using (OdbcConnection cn = new OdbcConnection("Driver={MySQL ODBC 3.51 Driver}; Server=localhost; Database=gymwebsite2; User=x; Password=x;")) { cn.Open(); using (OdbcCommand cmd = new OdbcCommand("INSERT INTO WallPosting (UserID, Wallpostings) VALUES (" + theUserId + ", '" + TextBox1.Text + "')", cn)) { cmd.ExecuteNonQuery(); } } PopulateWallPosts(theUserId); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload