Note that there are some explanatory texts on larger screens.

plurals
  1. POUpdating data in text boxes through a SQLDataSource
    primarykey
    data
    text
    <p>Using Visual Studio 2012 and SQL Server 2012</p> <p>Here is the situation:</p> <p>A website I am building is not updating data that is loaded into fields from a SQLDataSource. The data loads just fine into their appropriate text boxes, but when I go to edit the data and activate a button click, it looks like the revisions are cleared and the page refreshes to the original loaded data. As far as I can tell, my code looks correct, but that is obviously not the case.</p> <p>Addition info:</p> <p>I have the page set up in a containerplaceholder with a master page.</p> <p>Here is my mark up:</p> <pre><code>&lt;asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server"&gt; &lt;!-- Job Title --&gt; &lt;div class="lbljobtitle"&gt; &lt;asp:Label ID="lblJobTitle" runat="server" Text="Job Title"&gt;&lt;/asp:Label&gt; &lt;/div&gt; &lt;div class="txtjobtitle"&gt; &lt;asp:TextBox ID="txtJobTitle" runat="server" Height="22px" Width="250px"&gt;&lt;/asp:TextBox&gt; &lt;/div&gt; &lt;!-- Employee Type --&gt; &lt;div class="lblemployeetype"&gt; &lt;asp:Label ID="lblEmployeeType" runat="server" Text="Employee Type"&gt;&lt;/asp:Label&gt; &lt;/div&gt; &lt;div class="txtemployeetype"&gt; &lt;asp:TextBox ID="txtEmployeeType" runat="server" Height="22px" Width="250px"&gt;&lt;/asp:TextBox&gt; &lt;/div&gt; &lt;!-- Location --&gt; &lt;div class="lbllocation"&gt; &lt;asp:Label ID="lblLocation" runat="server" Text="Location"&gt;&lt;/asp:Label&gt; &lt;/div&gt; &lt;div class="txtlocation"&gt; &lt;asp:TextBox ID="txtLocation" runat="server" Height="22px" Width="250px"&gt;&lt;/asp:TextBox&gt; &lt;/div&gt; &lt;!-- Job Description --&gt; &lt;div class="lbljobdescription"&gt; &lt;asp:Label ID="lblJobDescription" runat="server" Text="Job Description"&gt;&lt;/asp:Label&gt; &lt;/div&gt; &lt;div class="txtjobdescription"&gt; &lt;asp:TextBox ID="txtJobDescription" runat="server" Height="160px" Width="250px" TextMode="MultiLine"&gt;&lt;/asp:TextBox&gt; &lt;/div&gt; &lt;!-- Requirements --&gt; &lt;div class="lblrequirements"&gt; &lt;asp:Label ID="lblRequirements" runat="server" Text="Requirements"&gt;&lt;/asp:Label&gt; &lt;/div&gt; &lt;div class="txtrequirements"&gt; &lt;asp:TextBox ID="txtRequirements" runat="server" Height="160px" Width="250px" TextMode="MultiLine"&gt;&lt;/asp:TextBox&gt; &lt;/div&gt; &lt;!-- Experience --&gt; &lt;div class="lblexperience"&gt; &lt;asp:Label ID="lblExperience" runat="server" Text="Experience"&gt;&lt;/asp:Label&gt; &lt;/div&gt; &lt;div class="txtexperience"&gt; &lt;asp:TextBox ID="txtExperience" runat="server" Height="22px" Width="250px"&gt;&lt;/asp:TextBox&gt; &lt;/div&gt; &lt;!-- Date Posted --&gt; &lt;div class="lbldateposted"&gt; &lt;asp:Label ID="lblDatePosted" runat="server" Text="Date Posted"&gt;&lt;/asp:Label&gt; &lt;/div&gt; &lt;div class="txtdateposted"&gt; &lt;asp:TextBox ID="txtDatePosted" runat="server" Height="22px" Width="250px"&gt;&lt;/asp:TextBox&gt; &lt;/div&gt; &lt;!-- Start Date --&gt; &lt;div class="lblstartdate"&gt; &lt;asp:Label ID="lblStartDate" runat="server" Text="Start Date"&gt;&lt;/asp:Label&gt; &lt;/div&gt; &lt;div class="txtstartdate"&gt; &lt;asp:TextBox ID="txtStartDate" runat="server" Height="22px" Width="250px"&gt;&lt;/asp:TextBox&gt; &lt;/div&gt; &lt;asp:Button ID="btnUpdate" runat="server" Text="Update Job" OnClick="btnUpdate_Click" /&gt; &lt;asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="&lt;%$ ConnectionStrings:bgrecruit_d01ConnectionString %&gt;" SelectCommand="SELECT job_title, employee_type, location, job_description, requirements, experience, date_posted, start_date, requisition_id FROM jobopening_tbl WHERE (requisition_id = @requisition_id)" UpdateCommand="UPDATE [jobopening_tbl] SET [job_title] = @job_title, [employee_type] = @employee_type, [location] = @location, [job_description] = @job_description, [requirements] = @requirements, [experience] = @experience, [date_posted] = @date_posted, [start_date] = @start_date WHERE [requisition_id] = @requisition_id"&gt; &lt;SelectParameters&gt; &lt;asp:QueryStringParameter Name="requisition_id" Type="String" QueryStringField="req_id" /&gt; &lt;/SelectParameters&gt; &lt;UpdateParameters&gt; &lt;asp:Parameter Name="job_title" Type="String" /&gt; &lt;asp:Parameter Name="employee_type" Type="String" /&gt; &lt;asp:Parameter Name="location" Type="String" /&gt; &lt;asp:Parameter Name="job_description" Type="String" /&gt; &lt;asp:Parameter Name="requirements" Type="String" /&gt; &lt;asp:Parameter Name="experience" Type="String" /&gt; &lt;asp:Parameter Name="date_posted" Type="String" /&gt; &lt;asp:Parameter Name="start_date" Type="String" /&gt; &lt;asp:Parameter Name="requisition_id" /&gt; &lt;/UpdateParameters&gt; &lt;/asp:SqlDataSource&gt; </code></pre> <p></p> <p>And my C#:</p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data.SqlClient; using System.Data; using System.Configuration; public partial class UpdateDetail : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { DataView dv = (DataView)SqlDataSource1.Select(DataSourceSelectArguments.Empty); DataRowView row = dv[0]; txtJobTitle.Text = row["job_title"].ToString(); txtEmployeeType.Text = row["employee_type"].ToString(); txtLocation.Text = row["location"].ToString(); txtJobDescription.Text = row["job_description"].ToString(); txtRequirements.Text = row["requirements"].ToString(); txtExperience.Text = row["experience"].ToString(); txtDatePosted.Text = row["date_posted"].ToString(); txtStartDate.Text = row["start_date"].ToString(); } protected void btnUpdate_Click(object sender, EventArgs e) { DataView dv = (DataView)SqlDataSource1.Select(DataSourceSelectArguments.Empty); DataRowView row = dv[0]; SqlDataSource1.UpdateParameters["job_title"].DefaultValue = txtJobTitle.Text.ToString(); SqlDataSource1.UpdateParameters["employee_type"].DefaultValue = txtEmployeeType.Text.ToString(); SqlDataSource1.UpdateParameters["location"].DefaultValue = txtLocation.Text.ToString(); SqlDataSource1.UpdateParameters["job_description"].DefaultValue = txtJobDescription.Text.ToString(); SqlDataSource1.UpdateParameters["requirements"].DefaultValue = txtRequirements.Text.ToString(); SqlDataSource1.UpdateParameters["experience"].DefaultValue = txtExperience.Text; SqlDataSource1.UpdateParameters["date_posted"].DefaultValue = txtDatePosted.Text; SqlDataSource1.UpdateParameters["start_date"].DefaultValue = txtStartDate.Text; //requisition_id = @requisition_id SqlDataSource1.UpdateParameters["requisition_id"].DefaultValue = row["requisition_id"].ToString(); SqlDataSource1.Update(); } </code></pre> <p>}</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.
 

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