我在尝试更新只有一条记录的表时遇到问题,我正在使用LINQ to SQL和两个文本框。我在页面加载时检索记录并在texbox中显示它们,我想在用户按下updateabout时更新表格但不更新。
DataClassesDataContext ss = new DataClassesDataContext();
protected void Page_Load(object sender, EventArgs e)
{
var about = (from p in ss.abouts select p).First();
if (!Page.IsPostBack)
{
txtaboutname.Text = about.title;
txtabouttext.Text = about.text;
}
}
protected void updateabout_Click(object sender, EventArgs e)
{
var about = (from p in ss.abouts select p).First();
about.title = txtaboutname.Text;
about.text = txtabouttext.Text;
ss.SubmitChanges();
}
答案 0 :(得分:1)
var query = from p in dc.Employee
select p;
foreach (Employee emp in query)
{
emp.Name = txtName.Text;
emp.ID = txtID.Text;
}
dc.SubmitChanges();
答案 1 :(得分:0)
试试这个
var about = from p in ss.abouts
select p;
foreach (abouts ab in about)
{
ab.title = txtaboutname.Text;
ab.text = txtabouttext.Text;
}
ss.SubmitChanges();
答案 2 :(得分:0)
我发现这个问题来自哪里:我忘了在表格中设置一个主键,然后我添加了主键并再次检查并解决了问题。