Note that there are some explanatory texts on larger screens.

plurals
  1. POUpdate database with values from textbox
    text
    copied!<p>i m trying to edit the values in database through textboxes in ASP.</p> <p>first i retrived the values from database and set those values to the value property of textboxes on the form so that user can see the old values.</p> <p>now, i want him to enter new values in the same textboxes and when he click on update the new values should be updated in the database.</p> <p>can any one tell what i have to do to get those new values???? when to submit the form????</p> <p>the code:</p> <pre><code>protected void Button2_Click(object sender, EventArgs e) { string MachineGroupName = TextBox2.Text; string MachineGroupDesc = TextBox3.Text; int TimeAdded = DateTime.Now.Hour + DateTime.Now.Minute + DateTime.Now.Second; if (MachineGroupName == "" || MachineGroupDesc == "") { Label2.Text = ("Please ensure all fields are entered"); Label2.Visible = true; } else { System.Data.SqlClient.SqlConnection dataConnection = new SqlConnection(); dataConnection.ConnectionString = @"Data Source=JAGMIT-PC\SQLEXPRESS;Initial Catalog=SumooHAgentDB;Integrated Security=True"; System.Data.SqlClient.SqlCommand dataCommand = new SqlCommand(); dataCommand.Connection = dataConnection; //tell the compiler and database that we're using parameters (thus the @first, @last, @nick) dataCommand.CommandText = ("UPDATE [MachineGroups] SET ([MachineGroupName]=@MachineGroupName,[MachineGroupDesc]=@MachineGroupDesc,[TimeAdded]=@TimeAdded) WHERE ([MachineGroupID]= @node)"); //add our parameters to our command object dataCommand.Parameters.AddWithValue("@MachineGroupName", MachineGroupName); dataCommand.Parameters.AddWithValue("@MachineGroupDesc", MachineGroupDesc); dataCommand.Parameters.AddWithValue("@TimeAdded", TimeAdded); dataConnection.Open(); dataCommand.ExecuteNonQuery(); dataConnection.Close(); } </code></pre>
 

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