Click here to Skip to main content
15,895,746 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have database with next tables:
SQL
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:
C#
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)
Posted
Updated 1-Oct-13 22:24pm
v3
Comments
tanweer 2-Oct-13 3:28am    
what is your issue, is there any exception, please explain little more
MK-Gii 2-Oct-13 3:30am    
Your question has a title "Saving data into SQL Server database". But your code does not have anything related with SQL server operations (INSERT, DELETE etc.). Publish more code.
Govindaraj Rangaraj 2-Oct-13 3:39am    
"but there is some kind of problem"

what kind? Please improve your question.
kneza9 2-Oct-13 4:26am    
To be honest I don't know what is the problem, application just stop working :(
Govindaraj Rangaraj 2-Oct-13 5:44am    
What is happening, is it throwing any exception?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900