Note that there are some explanatory texts on larger screens.

plurals
  1. POUpdate database table based on textbox values
    primarykey
    data
    text
    <p>I am trying to update database table based on text-box values.But i am unable to get new modified values in database.</p> <p>Here is my code which displays information in text-boxes coming from database</p> <pre><code>protected void Info() { string sID = Request.QueryString["ID"]; string sSql = "select * from [fn_Items]('"+sID+"')"; DataTable tbl1 = new DataTable(); string sEr = myClass.FillupTable(sSql, ref tbl1); if (tbl1.Rows.Count &gt; 0) { DataRow rd = tbl1.Rows[0]; txtName.Text = rd["Name"].ToString(); txtCategory.Text = rd["Category"].ToString(); DateTime mStart; DateTime mFinish; Boolean b = false; b = DateTime.TryParse(rd["start"].ToString(), out mStart); b = DateTime.TryParse(rd["end"].ToString(), out mFinish); txtStart.Text = mStart.ToString("dd-MMM-yyyy"); txtend.Text = mFinish.ToString("dd-MMM-yyyy"); txtDescription.Text = rd["Description"].ToString(); } } </code></pre> <p>Now when the user modifies the text-box data and clicks save, the data should change in the database. Here is my click_event:</p> <pre><code>protected void btnSave_Click(object sender, EventArgs e) { using (SqlConnection sqlConn = new SqlConnection("Data Source=MSSQLSERVER2008;Initial Catalog=Items_2;Persist Security Info=True;User ID=sa;Password=password")) { string query = "UPDATE tbl_Items SET Name = @Name,Category=@Category,start = @start, end = @End,Description = @Description where ID = @ID "; SqlCommand cmd = new SqlCommand(query, sqlConn); cmd.Parameters.AddWithValue("@ID",txtID.Text); cmd.Parameters.AddWithValue("@Name", txtName.Text); cmd.Parameters.AddWithValue("@Category", Category.Text); cmd.Parameters.AddWithValue("@start", txtStart.Text); cmd.Parameters.AddWithValue("@end",txtend.Text); cmd.Parameters.AddWithValue("@Description", txtDescription.Text); cmd.Connection.Open(); try { cmd.ExecuteNonQuery(); } catch (Exception ex) { throw new Exception("Error " + ex.Message); } } </code></pre> <p>Here while updating, in text-boxes I am getting the values present in the database where I need to get the modified values. How do I get the modified values instead?</p>
    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