修改
string t;
SqlConnection conn=new SqlConnection();
int empID = (int)DataList1.DataKeys[e.Item.ItemIndex];
//取得文本框中输入的内容
TextBox newTitle = (TextBox)e.Item.FindControl("TextBox1");
//定义SQL语句
string sqlCom = "update us set nam='" + newTitle.Text + "' where uid=" + empID ;
conn.ConnectionString="server=(local);user id=sa;pwd=sa;database=user";
conn.Open(); //定义命令对象
SqlCommand cmd = new SqlCommand(sqlCom,conn);
//打开数据连接
try
{
//执行SQL命令
cmd.ExecuteNonQuery();
//取消编辑
DataList1.EditItemIndex = -1;
DataList1.SelectedIndex=-1;
Sel();
}
catch(Exception err)
{
//输入异常信息
Response.Write(err.ToString());
}
finally
{
//关闭连接对象
conn.Close();
}