Note that there are some explanatory texts on larger screens.

plurals
  1. PObutton Postback and SQL SqlDataReader problem!
    primarykey
    data
    text
    <p>i am beginner with sql,</p> <p>I have comments Template with button in the end of it to add the new comment to the database ,so i use SQL INSERT code to add and it works fine. but after button postback , the the new comment does not shows in my label until i refresh the page manually! .</p> <p>this my code in c# code portion:</p> <pre><code> protected void Page_Load(object sender, EventArgs e) { ViewComments(); } private void ViewComments() { hookUp = new SqlConnection("Server=xxxx\\SQLEXPRESS;Database=WebExcerciseDB;" + "Integrated Security=True"); SqlCmd = new SqlCommand("SELECT PersonName,PersonMail,Comment FROM CommentsTable", hookUp); try { hookUp.Open(); reader = SqlCmd.ExecuteReader(); while (reader.Read()) { SQL_Result.Text += reader["PersonName"] + " " + reader["PersonMail"] + " " + reader["Comment"] + "&lt;br/&gt;"; } } catch (Exception) { MessageBox.Show("Error in database code\n"); } finally { reader.Close(); hookUp.Close(); } } protected void AddCommentBtn_Click(object sender, EventArgs e) { // SQL First INSRET Way // //string InsertSQLString = "INSERT INTO CommentsTable(PersonName,PersonMail,Comment,PostDate) VALUES ('" + // PersonName.Text + "','"+ PersonMail.Text + "','" + PersonComment.Value + "','" + // DateTime.Now + "')"; //hookUp = // new SqlConnection("Server=xxxx-PC\\SQLEXPRESS;Database=WebExcerciseDB;" + "Integrated Security=True"); //SqlCmd = new SqlCommand(InsertSQLString, hookUp); //hookUp.Open(); //SqlCmd.ExecuteNonQuery(); //hookUp.Close(); // SQL First INSRET Way End // // SQL second INSRET Way // string InsertSQLString = "INSERT INTO CommentsTable(PersonName,PersonMail,Comment,PostDate)VALUES(@Name,@Mail,@Comment,@Date)"; hookUp = new SqlConnection("Server=xxxx-PC\\SQLEXPRESS;Database=WebExcerciseDB;" + "Integrated Security=True"); SqlCmd = new SqlCommand(InsertSQLString, hookUp); SqlCmd.Parameters.Add("@Name", PersonName.Text); SqlCmd.Parameters.Add("@Mail", PersonMail.Text); SqlCmd.Parameters.Add("@Comment", PersonComment.Value); SqlCmd.Parameters.Add("@Date", DateTime.Now); hookUp.Open(); SqlCmd.ExecuteNonQuery(); hookUp.Close(); // SQL second INSRET Way End // } } </code></pre> <p>} </p> <p>thanks any way..</p>
    singulars
    1. This table or related slice is empty.
    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.
    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