Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Update Data

Posted on 2012-03-25
6
Medium Priority
?
332 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
[X]
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
  • 2
  • 2
  • 2
6 Comments
 
LVL 8

Assisted Solution

by:Eric Flamm
Eric Flamm earned 668 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 332 total points
ID: 37763083
use commit and savechanges methods.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 668 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

Question has a verified solution.

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

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
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…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

671 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