-1

我在尝试更新只有一条记录的表时遇到问题,我使用的是 LINQ to SQL 和两个文本框。我检索记录并在页面加载时将它们显示在 texboxes 中,并且我想在用户按下 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(); 

 }
4

3 回答 3

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();
于 2013-10-11T19:04:35.413 回答
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();
于 2013-10-11T01:17:04.730 回答
0

我发现这个问题来自哪里:我忘记在表中设置主键,我添加了主键并再次检查并解决了问题。

于 2013-10-13T10:16:17.627 回答