Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Update Data

Posted on 2012-03-25
6
326 Views
Last Modified: 2012-08-13
How to correct this command of C#?

public IQuery<student> GetStudentAge(int b)
{
    return this objectContext.students.???
}

What I want is to update all StudentAge to become the value of b. My table is student with the column StudentAge...
0
Comment
Question by:Whing Dela Cruz
  • 2
  • 2
  • 2
6 Comments
 
LVL 8

Assisted Solution

by:Eric Flamm
Eric Flamm earned 334 total points
ID: 37762830
Can you provide some additional context - is this in the code-behind of a page or a method in a class? Can you post the full code to enable some testing and review?
0
 

Author Comment

by:Whing Dela Cruz
ID: 37762856
Hi! What I'm trying to do is make some adjustment of the existing code below where it is all working only in single way of action. I want to update the data of the database in 1 click where the Whole age of the student will be updated... My XAML code are as follows
 
        private void btnupdate_Click(object sender, RoutedEventArgs e)
        {
            objctx = new StudentDomainContext();
            var studentid = int.Parse(searchstudentName.Text);
            var query = objctx.GetStudentsByIdQuery(studentid);
            objctx.Load(query, EDitData, null);
        }

        private void EDitData(LoadOperation<student> lo)
        {
            student st = lo.Entities.First();
            st.StudentName = txtstudentName.Text;
            st.StudentAge = int.Parse(txtstudentage.Text);
            try
            {
                objctx.SubmitChanges();
                MessageBox.Show("Data updated successfully!");
            }
            catch (Exception ex)
            {
                MessageBox.Show("Data updation failed due to " + ex.Message);
            }
        }

And the class are as follows;

  public IQueryable<student> GetStudentsById(int id)
        {
            return this.ObjectContext.students.Where(s=> s.ID == id);
        }

the code is working... But i want to update the data base of this code. Please tell me if this is possible? Thanks!
0
 
LVL 14

Assisted Solution

by:nishant joshi
nishant joshi earned 166 total points
ID: 37763083
use commit and savechanges methods.
0
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 14

Expert Comment

by:nishant joshi
ID: 37763087
after that use update method of table adapter and call update method.
0
 
LVL 8

Accepted Solution

by:
Eric Flamm earned 334 total points
ID: 37764332
It seems to me that your EditData method already updates the database, changing the student name and the student age based on the values in the respective text boxes.
objctx.SubmitChanges();

Open in new window

should be sufficient to save the changes, provided your StudentDomainContext object is configured correctly.

What are you trying to accomplish that your current application doesn't do?
0
 

Author Closing Comment

by:Whing Dela Cruz
ID: 37791895
Thanks!
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question