我用 linq 将我的 SQL 数据库连接到 sql,然后我创建了一个插入查询并调用InsertOnSubmit()
and SubmitChanges()
,它似乎很好,但我看不到插入的数据,表仍然是空的。我究竟做错了什么?
public Form1()
{
InitializeComponent();
DataClasses1DataContext db = new DataClasses1DataContext();
t_pupilid addRow = new t_pupilid();
int Num = db.t_pupilids.AsQueryable().Count();
if (Num == 0 )
addRow.pupId = 1;
else
{
var query =
from trc in db.t_pupilids
select trc.pupId;
addRow.pupId = query.Max() + 1;
db.t_pupilids.InsertOnSubmit(addRow);
}
db.SubmitChanges();
}