首页 新闻 会员 周边 捐助

linq to sqlite无法更新记录

0
悬赏园豆:50 [待解决问题]

1 /// <summary>
2 /// 修改记录
3 /// </summary>
4 /// <param name="info"></param>
5 /// <returns></returns>
6 public bool Update(News info)
7 {
8 bool flag = false;
9 using (model as IDisposable)
10 {
11 var selected = from x in model.News where x.ID == info.ID select x;
12 News row = selected.FirstOrDefault();
13 row.Title = info.Title;
14 row.SubTitle = info.SubTitle;
15 row.Advice = info.Advice;
16 row.Content = info.Content;
17 row.UpdateTime = info.UpdateTime;
18 row.Description = info.Description;
19 row.Enabled = info.Enabled;
20 row.FiledC1 = info.FiledC1;
21 row.FiledC2 = info.FiledC2;
22 row.FiledI1 = info.FiledI1;
23 row.FiledI2 = info.FiledI2;
24 row.Image = info.Image;
25 row.Keywords = info.Keywords;
26 row.LinkUrl = info.LinkUrl;
27 row.Sort = info.Sort;
28 row.Summary = info.Summary;
29 row.Top = info.Top;
30 row.TypeID = info.TypeID;
31 try
32 {
33 model.SubmitChanges();
34 flag = true;
35 }
36 catch (Exception)
37 {
38 flag = false;
39 }
40 }
41 return flag;
42 }
上面这个方法无法更新数据,但是说如果这样做

1 /// <summary>
2 /// 修改记录
3 /// </summary>
4 /// <param name="info"></param>
5 /// <returns></returns>
6 public bool Update(News info)
7 {
8 bool flag = false;
9 using (model as IDisposable)
10 {
11 var selected = from x in model.News where x.ID == info.ID select x;
12 News row = selected.FirstOrDefault();
13 row.Title = "ssssssssssssssssss"; //这里直接赋常量值便可以更新
14 row.SubTitle = info.SubTitle;
15 row.Advice = info.Advice;
16 row.Content = info.Content;
17 row.UpdateTime = info.UpdateTime;
18 row.Description = info.Description;
19 row.Enabled = info.Enabled;
20 row.FiledC1 = info.FiledC1;
21 row.FiledC2 = info.FiledC2;
22 row.FiledI1 = info.FiledI1;
23 row.FiledI2 = info.FiledI2;
24 row.Image = info.Image;
25 row.Keywords = info.Keywords;
26 row.LinkUrl = info.LinkUrl;
27 row.Sort = info.Sort;
28 row.Summary = info.Summary;
29 row.Top = info.Top;
30 row.TypeID = info.TypeID;
31 try
32 {
33 model.SubmitChanges();
34 flag = true;
35 }
36 catch (Exception)
37 {
38 flag = false;
39 }
40 }
41 return flag;
42 }
我之前以为是不能直接传一个model进去,就改成每一个字段就做为一个参数传进去,也还是不行。似乎是用变量传值就不行。各位有没有遇到过类似的问题。或者知不知道怎么解决呢?

think_fish的主页 think_fish | 初学一级 | 园豆:140
提问于:2011-03-24 17:15
< >
分享
所有回答(1)
1

换成 CYQ.Data 数据框架 吧,不用这么折腾。

路过秋天 | 园豆:4787 (老鸟四级) | 2011-03-25 11:49
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册