LINQ SubmitChanges 方法不更新数据库解决方法
LINQ SubmitChanges 方法不更新数据库
源码如下
public static string Select(int hotelid)
{
using (HotelDataContext hcon = new HotelDataContext())
{
var hotelinfo = hcon.hotel.SingleOrDefault<hotel>(s=>s.hotelid==hotelid);
return hotelinfo.hotelname;
}
}
public static void Edit(int hotelid)
{
using (HotelDataContext hcon = new HotelDataContext())
{
var hotelinfo = hcon.hotel.SingleOrDefault<hotel>(s=>s.hotelid==hotelid);
if (hotelinfo == null)
{
//===============
}
hotelinfo.hotelname = "修改后的酒店名";
hcon.SubmitChanges();
}
}
Edit(81408);
div1.InnerHtml = Select(81408);
更新不了 小弟 菜鸟 望高人不吝赐教!!不胜感激。
Answers
C# code
public static string Select(int hotelid)
{
HotelDataContext hcon = new HotelDataContext();
var hotelinfo = hcon.hotel.SingleOrDefault<hotel>(s=>s.hotelid==hotelid);
return hotelinfo==null "":hotelinfo.hotelname;
}
public static void Edit(int hotelid)
{
HotelDataContext hcon = new HotelDataContext();
var hotelinfo = hcon.hotel.SingleOrDefault<hotel>(s=>s.hotelid==hotelid);
if (hotelinfo != null)
{
hotelinfo.hotelname = "修改后的酒店名";
hcon.SubmitChanges();
}
}
Edit(81408);
div1.InnerHtml = Select(81408);