---
title: "Update not working C# ADO.net"  
description: "Update not working C# ADO.net"  
author: "Anonymous User"  
published: 2013-06-19  
updated: 2013-06-19  
canonical: https://www.mindstick.com/forum/1214/update-not-working-c-sharp-ado-dot-net  
category: "ado.net"  
tags: ["ado.net"]  
reading_time: 2 minutes  

---

# Update not working C# ADO.net

Hi Mindstickians, \
\
I've been at this for hours and cannot find the issue here. I have 3 pages, 2 of which have updates and are [working fine](https://answers.mindstick.com/qa/95550/why-is-the-safari-browser-not-working-fine), but this one not which I'm hoping someone might be able to find where the issue lies..\
\
Everything 'appears' to work, I see the 'sucessfully updated' message but it just does not update the data.\
\
Here are the [relevant](https://yourviews.mindstick.com/view/20439/big-data-issues-and-challenges-relevant-to-characteristics-of-big-data) snippets of code:\
\
ASCX:\
\
<asp:Repeater ID="TestDataList" runat="server" onItemCommand="Item_Command">\
<[ItemTemplate](https://www.mindstick.com/forum/2057/access-textbox-in-itemtemplate)>\
<div class='<%# Container.ItemIndex % 2 == 0 ? "list-wrap" : "list-wrap alternate" %>'>\
<a href="#" class="edit-list icon-pencil icon-large"></a>\
<div class="update">\
<span class="dl-content">\
<h2><asp:Label ID="TestNameDisplay" runat="server" CssClass="name" Text='<%# Eval("TestName") %>'/></h2>\
</span>\
<asp:[LinkButton](https://www.mindstick.com/forum/2100/linkbutton-to-expand-gridview-causes-row-colors-from-function-to-be-lost) ID="deleteTestCase" CssClass="delete-list icon-trash icon-large" runat="server" CommandName="deleteTestCase" CommandArgument='<\
\
%#Eval("TestCaseID")%>'/>\
\
<%--edit form--%>\
<span class="dl-update"> \
<asp:TextBox ID="TxtUpdateTestName" runat="server" CssClass='textEntry' Text='<%#Eval("TestName")%>'></asp:TextBox>\
<asp:LinkButton ID="EditTestNameButton" runat="server" Text="Save" CommandName="SelectTestName" CommandArgument='<%#Eval("TestCaseID")%>' \
\
ValidationGroup='<%# "UpdateTestCaseName" + Eval("TestCaseID") %>' />\
<asp:RequiredFieldValidator ID="UpdateTestNameRequired" runat="server" ControlToValidate="TxtUpdateTestName" CssClass="formValidation" \
\
ErrorMessage="What good is a test case with no name?" ValidationGroup='<%# "UpdateTestCaseName" + Eval("TestCaseID") %>'/>\
</span>\
</div>\
</ItemTemplate>\
</asp:Repeater>\
[Code Behind](https://www.mindstick.com/forum/2199/call-javascript-s-function-from-code-behind):\
\
protected void Item_Command(Object sender, RepeaterCommandEventArgs e)\
{\
if (e.CommandName == "SelectTestName")\
{\
string setTestNameSQL = "UPDATE TestCases SET TestName = @TestName WHERE TestCaseID = " + e.CommandArgument;\
\
[SqlConnection](https://www.mindstick.com/forum/1209/sqlconnection-sqlcommand-sqldatareader-idisposable) conn = new SqlConnection(GetConnectionString());\
[SqlCommand](https://www.mindstick.com/forum/91/difference-between-sqlcommand-and-sqlcommandbuilder) cmdUpdateTestName = new SqlCommand(setTestNameSQL, conn);\
\
TextBox tb = (TextBox)e.Item.FindControl("TxtUpdateTestName");\
\
[SqlParameter](https://www.mindstick.com/forum/12652/how-to-set-typename-in-the-constructor-of-new-sqlparameter) u1 = new SqlParameter("TestName", tb.Text);\
SqlParameter u2 = new SqlParameter("TestCaseID", e.CommandArgument);\
\
cmdUpdateTestName.Parameters.Add(u1);\
cmdUpdateTestName.Parameters.Add(u2);\
\
try\
{\
conn.Open();\
cmdUpdateTestName.ExecuteNonQuery();\
PopulateTestList();\
lblUserFeedbackMessage.Text = "Sucessfully updated!";\
}\
catch (System.Data.SqlClient.SqlException ex)\
{\
string msg = "[Update Error](https://answers.mindstick.com/qa/95209/how-do-i-fix-an-outlook-update-error):";\
msg += ex.Message;\
throw new [Exception](https://www.mindstick.com/articles/1824/objective-c-exception-handling)(msg);\
}\
finally\
{\
conn.Close();\
}\
}\
\
Thanks in advance for any recommendations or solutions.

## Replies

### Reply by Sumit Kesarwani

Hi,\
try as following\
**string setTestNameSQL = "UPDATE TestCases SET TestName = @TestName WHERE TestCaseID = @TestCaseID";****\****SqlConnection conn = new SqlConnection(GetConnectionString());****SqlCommand cmdUpdateTestName = new SqlCommand(setTestNameSQL, conn);****\****TextBox tb = (TextBox)e.Item.FindControl("TxtUpdateTestName");****\****SqlParameter u1 = new SqlParameter("@TestName", tb.Text);****SqlParameter u2 = new SqlParameter("@TestCaseID", e.CommandArgument);****\****cmdUpdateTestName.Parameters.Add(u1);****cmdUpdateTestName.Parameters.Add(u2);**\
Otherwise you don't provide the values for the parameters, because the @ is missing and your command is vulnerable for an sql injection attack.\


---

Original Source: https://www.mindstick.com/forum/1214/update-not-working-c-sharp-ado-dot-net

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
