saving data from tables to database
I am writing a database Application in .NET. My application reads data from SQL Server with LINQ. It then saves my data in DataSet(in tables). When user does something in application the data is saved in DataSet(in tables). After some transactions user can save data in Database(The data send from dataset to database).But there is a problem:
For example I have 2 tables in dataset which is read from database: Bank Account And IncomeTransactions.
- BankAccount saves all my bank accounts.
- IncomeTransaction is for saving my incomes to my Accounts
- that is why I have a foreign key in IncomeTransaction table(IDACCOUNT)).
Then I add a new account to my Account Table(not database). After that I add a new IncomeTransaction to my IncomeTransaction table. The added IncomeTransaction's IDACCOUNT is the new Account's ID.
Everything up to this step is OK. But when I try to save th开发者_如何学Pythone data to the database via LINQ, I'm getting the following error:
The INSERT statement conflicted with the FOREIGN KEY constraint "FK_Income_Accounts". The conflict occurred in database "HouseBudget", table "dbo.Accounts", column 'IDAccount'. The statement has been terminated.
How can I solve this error?
add data for column IDAccount in table dbo.Accounts along with changes that you do when creating new account. (The added incometransaction's IDACCOUNT is the new Account's ID.)
精彩评论