I have database with next tables:
Item:
-ItemID
-Category
-Brand
-Condition
UserItem:
-UserItemID
-ItemName
-ItemPrice
-ItemFK
As you can see tables are connected with relationship one-many.
I wrote code to add information from wpf form to database, but there is some kind of problem.
I don't know where is a problem, so can you give me some useful advice. Thanks
The code is following:
Item i = new Item
{
Category = textBox1.Text,
Brand = textBox2.Text,
Condition = comboBox1.SelectedValue.ToString()
};
au.AddToItem(i);
au.SaveChanges();
var adi = (from it in au.Item select it).Last();
UserItem ui = new UserItem
{
Username = use.Username,
UserID = use.UserID,
ItemName = textBox3.Text,
ItemPrice = Convert.ToDecimal(textBox4.Text),
LastBidder = "None",
Time = DateTime.Now,
UserFK = 1,
ItemFK = adi.ItemID
};
au.AddToUserItem(ui);
au.SaveChanges();
MessageBox.Show("Item is added");
this.Close();
Sorry
I am using EDM(Entity Data Model) to save data into SQL Server. Code above is about to happen when user click add item button. The problem is that when user click the button application stop work. (Sorry for language)