AspdotnetCodes.com
Search
Articles
Books
Resources
Asp.Net News
Downloads
Free Tech Magazines
Asp.Net Web Hosting
Archives
Softwares
Newsletter
Suggest Us
Link to Us
Feeds Subscription
Articles
Questions & Answers
Tips & Tricks
 Trouble with database synchronization
Posted by Babak Asgharian on  11/1/2008 5:57:00 PM Category: Asp.Net 2.0
Add to my favorites
Email to friend
I am using c# language, visual studio 2008. I am making a fitness app with a Client table, WorkoutJournal table, and FoodJournal table. I am using a gridview to display the food and workout journals.

Lately I have run into a problem where:
I add a data entry to a Journal
View Journal <--- here it wont display new item so....
I manually open the database in the server explorer.
Now I refresh to view journal again and the new entry now displays.

Any ideas why this doesnt automatically show while I'm running the program?
(also pls note: my gridview edit, update, delete, cancel all works perfect. Also I can add a client and instantly view it on the client gridview perfectly as well. I am thinking there is problem with the child data tables connection?)

protected void Button1_Click(object sender, EventArgs e)
{
FoodJournal journal = new FoodJournal();
journal.Calories = this.uxTextBoxCalories.Text;
journal.Food = this.uxTextBoxFood.Text;
journal.Id_Client = this.GetMemberID();
journal.MealTime = this.Calendar1.SelectedDate;
journal.Carbs = this.uxTextBoxCarbohydrates.Text;
journal.Protein = this.uxTextBoxProtein.Text;
journal.Fat = this.uxTextBoxFat.Text;
try
{
Text2FitService.SaveFoodJournal(journal);
}
catch(Exception ex)
{

this.uxTextBoxFood.Text = "SAVE FAILED!!!!!!!!!";
}
//set textboxes to blank values when done updating
this.uxTextBoxCalories.Text="";
this.uxTextBoxFood.Text="";
this.uxTextBoxCarbohydrates.Text="";
this.uxTextBoxProtein.Text="";
this.uxTextBoxFat.Text="";
}
Here is from my Services.cs
public static void SaveFoodJournal(FoodJournal journal)
{

_context.FoodJournals.InsertOnSubmit(journal);
_context.SubmitChanges();

}


Post Your Reply Post New Question

 Viewer's Reply
Call your Data Bind method
Answered By Moderator1 on 11/4/2008 7:59:15 AM
Everytime you do database manipulation, then you have to call the Data Binding methods for the GridView to show the changes affected.

If you are using SQLDataSource, then use the below syntax after you call save methods.

SqlDataSource1.DataBind();
 
Oops. I had figured this out.
Answered By Babak Asgharian on 11/4/2008 8:43:49 AM
I had to change my data source to LINQ to fix the problem and all went well. Why I had to do this will always be unknown..
 
Post Your Reply If you still have problem, post it again under this reply for better response.

 
Sponsored by
When Good HTML Goes Bad: How You Can Protect Your Web Applications
FierceDeveloper
Sexy Web Design - Free 71 Page Preview!