C# 使用新字符串更新数据表

C# 使用新字符串更新数据表,c#,asp.net,web-services,onchange,C#,Asp.net,Web Services,Onchange,我更改了以下text事件- protected void DataList1_SelectedTextChanged(object sender, EventArgs e) { TextBox chk = (TextBox)sender; DataListItem item = (DataListItem)chk.NamingContainer; TextBox txt = (TextBox)DataList1.Items[item.I

我更改了以下
text
事件-

 protected void DataList1_SelectedTextChanged(object sender, EventArgs e)
    {
        TextBox chk = (TextBox)sender;
        DataListItem item = (DataListItem)chk.NamingContainer;

        TextBox txt = (TextBox)DataList1.Items[item.ItemIndex].FindControl("aTextBox");
        string text = txt.Text;

        WebService1 ws = new WebService1();
        ws.updateA(text, newText)

    }
其中,
ws.updateA
web方法需要
text
,这是文本框中的原始文本,
newText
是触发更改事件后的文本

我的问题是,当web方法使用新文本更新数据表时,如何区分原始文本和要在web方法中使用的新文本

SQL是-

UPDATE table SET term='" + newText + "' WHERE termText= '" + text + "'

您确实应该使用主键来标识要更新的行。通过where子句中的文本字符串进行更新不是一种好的做法

当触发
SelectedTextChanged
事件时,控件的旧值在页面生命周期中被长期覆盖

如果知道旧值很关键,那么应该使用
ViewState
跨回发


请参阅:

因此sql中存在需要旧值的问题。这是胡说八道,因为数据库最了解所有旧值。要识别记录,您通常使用主键。也许我需要更好的update语句?您需要更好的数据库模型。此表的主键是什么?通常,您会使用一个连续的数字(在SQL Server
IDENTITY(1,1)
)作为主键,然后使用此数字作为记录的标识符。那么就不需要使用
术语
列来识别它。@Jambo说SQL确实易受攻击。我现在意识到我应该使用标识值而不是原始文本:/