SubmitChanges Get back record immediately

98 views Asked by At

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();
1

There are 1 answers

0
Kirk Woll On BEST ANSWER

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, the IsDbGenerated property of the corresponding [Column] attribute should be true (though if you ran it through the designer, it would already be there).