SubmitChanges 立即取回记录
我有一个向数据库添加记录的表单。主键是自动递增的。我想让网页重定向到显示刚刚输入的信息的页面。
例如,如果以下情况,它将重定向到 http://localhost/details.aspx?softwareID=1019 1019 是下一个生成的数字。
这是将其提交给数据库的代码。
software software = new software
{
EQCN = txtEQCN.Text,
title = txtTitle.Text,
version = txtVersion.Text,
license = txtLicense.Text,
expirationDate = txtExpirationDate.Text
};
db.softwares.InsertOnSubmit(software);
db.SubmitChanges();
I have a form that adds a record to the database. The primary key is auto incremented. I would like to have the web page redirect to the page that displays the information that was just entered.
For example, it would redirect to http://localhost/details.aspx?softwareID=1019 if 1019 was the next number generated.
Here is the code that submits it to the DB.
software software = new software
{
EQCN = txtEQCN.Text,
title = txtTitle.Text,
version = txtVersion.Text,
license = txtLicense.Text,
expirationDate = txtExpirationDate.Text
};
db.softwares.InsertOnSubmit(software);
db.SubmitChanges();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Linq-To-Sql 开箱即用地支持此功能。调用
SubmitChanges
后,与您的 PK 对应的属性值应该具有新值。特别是,相应[Column]
属性的IsDbGenerate
属性应该为 true(尽管如果您通过设计器运行它,它已经在那里了)。Linq-To-Sql supports this out of the box. After calling
SubmitChanges
the value of your propety that corresponds to your PK should have the new value. In particular, theIsDbGenerated
property of the corresponding[Column]
attribute should be true (though if you ran it through the designer, it would already be there).