Solved

Update Data

Posted on 2012-03-25
6
323 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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

706 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now